我正在尝试使用 PDO 更新 MySQL 中字段的值,我尝试过使用不同类型的准备好的语句,但它们都不起作用。这是我的代码:
$table = $_POST['table'];
$field = $_POST['field'];
$value = $_POST['value'];
try{
$available = "Available";
$cero = 0;
$q = "UPDATE ? SET $available = $cero WHERE ? = ? ";
$stmt = $connection->getPdo()->prepare($q);
$stmt->execute( array ($table,$field,$value) );
echo true;
}catch(PDOException $exception){
echo $exception;
}
问题解决了:
$q = "UPDATE $table SET $available = $cero WHERE $field = ? ";
$stmt = $connection->getPdo()->prepare($q);
$stmt->execute( array ($value) );