php - 使用查询更新 PDO 中的表时出现语法错误

标签 php mysql pdo syntax-error

<分区>

PHP 代码使用带有准备好的语句的 PDO 查询来更新我的表的部分。

收到的错误是:

Array ( 
  [0] => 42000 
  [1] => 1064 
  [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `EditID` = 13' at line 3 
)

但是,我不确定语法错误的性质是什么。

这是我的 PHP 代码:

<?php
$pdo=new PDO("mysql:dbname=createyo_TestDatabase;host=localhost","createyo_james","password");
$statement=$pdo->prepare("UPDATE `Edits` SET `Rep` = :Reputation, WHERE `EditID` = :EditID");

$statement->bindValue(':Reputation', (int) trim($_GET['Reputation']), PDO::PARAM_INT);
$statement->bindValue(':EditID', (int) trim($_GET['EditID']), PDO::PARAM_INT);
$statement->execute() or die(print_r($statement->errorInfo()));

$results=$statement->fetchAll(PDO::FETCH_ASSOC);
$json=json_encode($results);
print $json;
?>

最佳答案

SET 后面不需要逗号:

"UPDATE `Edits` SET `Rep` = :Reputation, WHERE `EditID` = :EditID"

应该是:

"UPDATE `Edits` SET `Rep` = :Reputation WHERE `EditID` = :EditID"

关于php - 使用查询更新 PDO 中的表时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25335370/

相关文章:

php - Laravel 5 firstOrCreate keep create even set unique to the field

php - mysql中的getdate()

php - 从具有 .htaccess 限制下载的文件夹中播放 mp3

php - 根据另一个表mysql的顺序动态更改表数据

MYSQL: ALTER TABLE DROP FOREIGN KEY 基于 SELECT 结果

php - 从 url 抓取变量

php - 如何将 JSON_INSERT 与字符串中的键一起使用?

php - 使用PDO提取单行,单列

php - DataTables 1.10 服务器端,表连接返回 'null' 值响应

使用过程插入行时 PHP MYSQL PDO lastInsertId 返回 0