2014-01-13 61 views
0

IM使用的MySQL寫一個應用程序,檢查用戶狀態 IM,我想有一個表名檢查無法插入到表(PHP的MySQL)

這是我的代碼:

mysqli_report(MYSQLI_REPORT_ALL); 
$stmt = $mysqli->prepare("INSERT INTO check VALUES (?,?)"); 

我得到錯誤:

Uncaught exception 'mysqli_sql_exception' with message '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 'check VALUES (?,?)' at line 1' 

我在做什麼錯了?

回答

1

你的表名(檢查)

是在MySQL的保留字。

環繞它在反引號像這樣:

$mysqli->prepare("INSERT INTO `check` VALUES (?,?)"); 
1

check是MySQL中的reserved word。用反引號括起來!

像這樣

mysqli_report(MYSQLI_REPORT_ALL); 
$stmt = $mysqli->prepare("INSERT INTO `check` VALUES (?,?)");