Symfony DBAL 插入给出:"Syntax error or access violation: 1064"

Symfony DBAL insert gives: "Syntax error or access violation: 1064"

我正在尝试将一些数据插入数据库,但这里有些问题。无法理解它是什么,我希望有人能告诉我这个是怎么回事。

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

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
             ));

"$this->orderid"为字符串变量,"$this->totalweight"为整数

它给出了这个错误信息:

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 上执行相同的查询并且有效,但这个不行。这到底是怎么回事?

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

您必须在单词周围使用反引号以防止出现此错误。但更好的建议是在 table.

前加上前缀