【发布时间】:2018-01-14 03:22:30
【问题描述】:
看过很多类似的问题,但还是不知道发生了什么。
我正在使用 PHP 的 PDO 来准备这样的语句:
try{
$statement = $db->prepare("INSERT INTO $date (name, surname, email, phone, comment) VALUES (:name, :surname, :email, :phone, :comment)");
$statement->bindParam(':name', $name);
$statement->bindParam(':surname', $surname);
$statement->bindParam(':email', $email);
$statement->bindParam(':phone', $phone);
$statement->bindParam(':comment', $comment);
$statement->execute();
}
catch(PDOException $e){
die("Connection to database failed: " . $e->getMessage());
}
已尝试使用 [] 转义所有内容并在表名之前指定数据库名称,但不断得到
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 '2017-08-11 (name, surname, email,
phone, comment) VALUES ('Test', 'Test', 'Test@' at line 1
【问题讨论】:
-
表名
2017-08-11是无效的,如果你真的有一个以日期为名字的表(如果是这样我很好奇为什么)你需要用引号将它包裹起来 -
谢谢!这只是一个简单的预订系统,每天有一张桌子。
标签: php mysql sql pdo syntax-error