Reputation: 1396
I'm trying to insert some data into database, but something is off here. Cannot catch what it is and I'm hoping someone might be able to tell me what's going on with this one.
My table looks somewhat like this:
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
I'm using Symfony2-framework and it's DBAL-insert here:
$conn->insert('order', array(
'order_ordernumber' => $this->orderid,
'order_orderweight' => $this->totalweight
));
"$this->orderid" is string variable, and "$this->totalweight" is int.
And it gives this error-message:
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 »
I can do the same query on pure sql and it works, this one doesn't. What on earth is going on with this one?
Upvotes: 1
Views: 1398
Reputation: 4012
order
is a reserved keyword in MySQL : http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html
You have to use backquotes arround the word to prevent this error. But a better recommendation would be to prefix your table.
Upvotes: 4