運行到我看不到的問題。PHP PDO語法錯誤或訪問衝突:1064
這裏是我的功能
function addIT($type, $amount, $id) {
$db = new database();
$conn8 = $db->connect();
$addit = $conn8->prepare("UPDATE accountTable SET :type = :type + :amount WHERE ID = :id");
$addit->execute(array('type'=>$type, 'amount'=>$amount, 'id'=>$id));
}
繼承人的電話我做:
$type = "age";
$amount = 17;
$id = 1;
addIT($type, $amount, $id);
現在
當執行它給了我下面的錯誤
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 ''age' = 'age' + '17' WHERE ID = '1'' at line 1' in /Library/WebServer/Documents/me/functions/activity.php:7 Stack trace: #0 /Library/WebServer/Documents/me/functions/activity.php(7): PDOStatement->execute(Array) #1 /Library/WebServer/Documents/me/content/doadd.php(66): addIT('age', 17, '1') #2 /Library/WebServer/Documents/me/main(48): include('/Library/WebSer...') #3 /Library/WebServer/Documents/me/where.php(25): include('/Library/WebSer...') #4 {main} thrown in /Library/WebServer/Documents/me/functions/activity.php on line 7
的代碼,我敢肯定,有件事我的執行或準備聲明中出現錯誤。我再也看不到它了。
在查詢中不能有變量列或表名 –
根本不應該有$ conn8變量。以及任何其他$ connN –