我有这样的代码:未知的SQL语法错误PHP PDO
try {
$sql = "INSERT INTO order(
user_id,
departure_street,
departure_housenr,
departure_postalcode,
departure_city,
arrival_street,
arrival_housenr,
arrival_postalcode,
arrival_city,
order_date,
lifter,
order_status
)
VALUES(
:user_id,
:departure_street,
:departure_housenr,
:departure_postalcode,
:departure_city,
:arrival_street,
:arrival_housenr,
:arrival_postalcode,
:arrival_city,
:order_date,
:lifter,
:order_status
)";
$stmt = $dbh -> get_instance() -> prepare($sql);
$stmt -> execute(array(':user_id' => $_SESSION[ 'user_id' ],
':departure_street' => $street1_parsed,
':departure_housenr' => $streetnumber1,
':departure_postalcode' => $postcode1,
':departure_city' => $city1_parsed,
':arrival_street' => $street2_parsed,
':arrival_housenr' => $streetnumber2,
':arrival_postalcode' => $postcode2,
':arrival_city' => $city1_parsed,
':order_date' => $datetime,
':lifter' => $lifter,
':order_status' => $order_status));
}
catch(PDOException $e) {
echo $e -> getMessage() . '<br />' . $sql;
}
此代码一直给我这个错误:
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 'order( user_id, departure_street, ' at line 1
我不明白什么可以是错误的语法。我已经使用了这个查询很多次了,它总是有效的。现在有什么问题?我试图通过echo
变量$sql
来查看结果查询的结果,但它并未显示正在插入的值。任何人都可以看到SQL语法错误?
订单是保留字MySQL如此包装内''(反引号) –
你打印你的'查询'??? – Karthi
@AbhikChakraborty该死的,这是第二次一个保留的SQL关键字把我搞砸了。谢谢:) –