我检查了多个PDO帖子,他们都说这个语法不正确,但即使在检查时我似乎无法找到它。 这里是我的代码:PDO重复更新错误
$stmt = $pDatabase->prepare('INSERT INTO Agenda (index, date, shortdesc) VALUES :values ON DUPLICATE KEY UPDATE date=VALUES(date), shortdesc=VALUES(shortdesc)');
我试图在最后一个;
修复它,或者在一次插入一个。它准备上的错误,所以无论:values
应该甚至不重要。
这是产生的误差:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'index, date, shortdesc) VALUES(?, ?, ?)ON DUPLICATE KEY UPDATE date=VALUES(date)' at line 1' in /customers/f/b/e/**************/httpd.www/editagenda.php:14 Stack trace: #0 /customers/f/b/e/**************/httpd.www/editagenda.php(14): PDO->prepare('INSERT INTO Age...') #1 {main} thrown in /customers/f/b/e/**************/httpd.www/editagenda.php on line 14
其中14是prepare
线。
此行在DBadmin中正常工作。
我的表看起来像这样:
index date shortdesc longdesc boolean
10 2015-12-12 Something copyshort 1
11 2015-11-12 Somethi2ng copyshort2 0
错误消息中的SQL与您发布的SQL不同。 '$ stmt'中没有'VALUES(?,?,?)'。 – Barmar