'PDOException' 语法错误或访问冲突:1064 您的 SQL 语法有错误;查看 [英] 'PDOException' Syntax error or access violation: 1064 You have an error in your SQL syntax; check

查看:86
本文介绍了'PDOException' 语法错误或访问冲突:1064 您的 SQL 语法有错误;查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试将订单的详细信息提交到我的数据库时,我不断收到以下错误:

<块引用>

致命错误:未捕获的异常 'PDOException' 带有消息 'SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在/home/ubuntu/workspace/handlers/checkout-handler.php 中的 111 行 PDOException: SQLSTATE[42000]: 语法错误或访问冲突:1064 附近使用的正确语法您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的order (order_details, order_address, cust_id, cust_name, delivery_type,paid)"附近使用的正确语法.

我不知道有什么问题,所有的变量都被正确地发布到页面上.

$query1 = "INSERT INTO order (order_details, order_address, cust_id, cust_name, delivery_type,paid) VALUES(:details,:address,:d,:name,:delivery,:paid);";$sql=$conn->prepare($query1);$sql->bindParam(':details', $details);$sql->bindParam(':address', $address);$sql->bindParam(':name', $name);$sql->bindParam(':delivery', $delivery_type);$sql->bindParam(':paid', $paid);$sql->bindParam(':d', $d);$sql->execute();

解决方案

order 是保留关键字.您应该在它周围添加反引号 ` 以使用它:

$query1 = "INSERT INTO `order` (order_details, order_address, cust_id, cust_name, delivery_type,paid)VALUES(:details,:address,:d,:name,:delivery,:paid);";$sql = $conn->prepare($query1);

另见:关键字和保留字

I keep getting the following error when trying to submit details of an order into my database:

Fatal error: Uncaught exception 'PDOException' with message '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 ' in /home/ubuntu/workspace/handlers/checkout-handler.php on line 111 PDOException: 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 (order_details, order_address, cust_id, cust_name, delivery_type, paid) ' at line 1.

I can't figure out whats wrong with it, all of the variables are being posted correctly to the page.

$query1 = "INSERT INTO order (order_details, order_address, cust_id, cust_name, delivery_type, paid) VALUES(:details,:address,:d,:name,:delivery,:paid);";                                         
$sql=$conn->prepare($query1);
$sql->bindParam(':details', $details);
$sql->bindParam(':address', $address);
$sql->bindParam(':name', $name);
$sql->bindParam(':delivery', $delivery_type);
$sql->bindParam(':paid', $paid);
$sql->bindParam(':d', $d);
$sql->execute();

解决方案

order is a reserved keyword. You should add backticks ` around it to use it:

$query1 = "INSERT INTO `order` (order_details, order_address, cust_id, cust_name, delivery_type, paid) 
           VALUES(:details,:address,:d,:name,:delivery,:paid);";                                         
$sql = $conn->prepare($query1);

See also : Keywords and Reserved Words

这篇关于'PDOException' 语法错误或访问冲突:1064 您的 SQL 语法有错误;查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆