小编NoS*_*ock的帖子

PDO MySQL编写了INSERT语法错误

已经看到了大量类似的问题,但仍然无法找出正在发生的事情.

我正在使用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());
}
Run Code Online (Sandbox Code Playgroud)

尝试使用[]转义所有内容并在表名前指定数据库名称,但继续获取

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) …
Run Code Online (Sandbox Code Playgroud)

php mysql sql pdo syntax-error

2
推荐指数
1
解决办法
386
查看次数

标签 统计

mysql ×1

pdo ×1

php ×1

sql ×1

syntax-error ×1