1
我試圖插入一些數據到數據庫,但有些東西在這裏。無法捕捉它是什麼,我希望有人能夠告訴我這一次發生了什麼。Symfony DBAL插入給出:「語法錯誤或訪問衝突:1064」
我的表看起來有點像這樣:
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的框架,它的DBAL插入此處
$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相同的查詢和它的作品,這一次沒有。這件事究竟在發生什麼?
'order'是MySQL中的一個保留關鍵字,您應該在您的表格前加以防止出現此類錯誤。 –
如果這是關於保留關鍵字,純粹的sql如何工作? – GotBatteries
您需要使用反引號保留字'order' insert>('order'' –