php - Avoiding SQL injection in delete API function -



php - Avoiding SQL injection in delete API function -

i'm trying build android app, , part of app involves crud options on database need synced server. have cru bits sorted, trying deletes in such way avoid sql injection.

i have used prepared statements other queries, wondering whether next method doesn't safe:

i have defined list of tables on delete query valid, along list of primary keys on tables can nowadays in tablekey field. utilize prepared statement using value provided in tablekeyvalue field, along restricting operations acting on individual user's id.

is methodology safe sql injection point of view, or should set specific api endpoints each of tables deleted from, , pass through id value used in traditional prepared statement?

($i = 0; $i < count($deletearray); $i++) { if (in_array($deletearray[$i]['tablename'], $this->table_array) && in_array($deletearray[$i]['tablekey'], $this->key_array)) { $deletestmtsql = "delete ".$deletearray[$i]['tablename']." ".$deletearray[$i]['tablekey']." = ? , userid = ?"; $deletestmtsth = $this->dbh->prepare($deletestmtsql); $deletestmtdata = array( $deletearray[$i]['tablekeyvalue'], $userid ); $deletestmtsth->execute($deletestmtdata); $j++; } }

based on comments lxg , david, solution have come with:

i pass in tablename, tablekey , tablekeyvalue generic method, which, after confirming tablename , tablekey match up, passes tablekeyvalue private method

(e.g. deletefromtablexbykey($tablekeyvalue) uses prepared statement, taking key value.

if values passed parent function tablename , tablekey not match predefined list, pass through no farther interaction, , error message returned.

php mysql sql security mysqli

Comments

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -