2014-01-13 124 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 (?,?)");