简体   繁体   中英

sql update statement fails

I have an update sql statement that fails and I don't know the reason..

Is there anything wrong with:

<?php
extract($_POST);
if ($req = $db->prepare("UPDATE {$sTable} SET ? = ? WHERE id=?")) {
    $req->bind_param("ssi", $columnName, $value, $id );
    $req->execute();
}
?>

If you bind column as string param, your query will look like:

UPDATE some_table SET 'column' = 'value' WHERE id=1

which is of course wrong. So the answer is you cannot bind column (or table) as parameter in prepared statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM