Symfony DBAL插入提供:"语法错误或访问冲突:1064"

时间:2015-05-21 09:54:40

标签: php mysql symfony dbal

我试图将一些数据插入到数据库中,但这里有些东西。无法理解它是什么,我希望有人能够告诉我这个是怎么回事。

我的表看起来有点像这样:

CREATE TABLE IF NOT EXISTS `db_name`.`order` (
  `orderID` INT NOT NULL AUTO_INCREMENT,
  `order_ordernumber` VARCHAR(200) NOT NULL,
  `order_orderweight` INT NOT NULL,
  ... And other columns as well, but all NULL
ENGINE = InnoDB

我在这里使用Symfony2-framework及它的DBAL-insert:

$conn->insert('order', array(
              'order_ordernumber' => $this->orderid,
              'order_orderweight' => $this->totalweight
             ));

" $这 - >订单ID"是字符串变量," $ this-> totalweight"是int。

它给出了这个错误信息:

An exception occurred while executing 'INSERT INTO order (order_ordernumber, order_orderweight) VALUES (?, ?)' with params ["000001", 900]:

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_ordernumber, order_orderweight) VALUES ('000001', '900')' at line 1
500 Internal Server Error - DBALException
1 linked Exception: PDOException » 

我可以在纯sql上做同样的查询,但它确实有效,这个没有。究竟是怎么回事?

1 个答案:

答案 0 :(得分:3)

order是MySQL中的保留关键字:http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html

你必须在单词周围使用反引号来防止此错误。但更好的建议是在你的桌子前加上。