在phpMyAdmin,我可以通過SQL運行此:PHP PDO在他們的名字選擇用單引號列
SELECT * FROM mytable WHERE `Bob's Stuff` > 1
但是,當我運行完全相同的查詢PHP腳本:
$stmt->prepare("SELECT * FROM mytable WHERE `Bob's Stuff` > :int");
$stmt->bindValue(':int', $int);
$stmt->execute();
我得到這個錯誤:
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 MySQL server version for the right syntax to use near ':int AND
Bob's Stuff
>= '1')' at line 10' in script.php:208 Stack trace: #0 script.php(208): PDOStatement->execute() #1 {main} thrown in script.php on line 208
如果我將查詢列更改爲任何其他列名稱,查詢工作正常。
是否有可能具有撇號的列名?
恕我直言,有一個列或一個表中用撇號命名是錯誤的... –