krvajal krvajal - 2 months ago 5
MySQL Question

SQL query error for datetime object

I am trying to execute this query into my sql database

'INSERT INTO ba_shop_opening (day, from, to) VALUES (?, ?, ?)' with params ["mon", "1970-01-01 00:00:00", "1970-01-01 00:00:00"]:


and I am getting the following error

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 'from, to) VALUES ('mon', '1970-01-01 00:00:00', '1970-01-01 00:00:00')' at line 1


Here is the DDL of the table I am working with

CREATE TABLE `ba_shop_opening` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`from` datetime NOT NULL,
`to` datetime NOT NULL,
'day' VARCHAR(20) NOT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci


I don't understand what the problem. Any help will be appreciated.

Answer

from is a reserved word. I'd recommend you rename the column in the table.

https://dev.mysql.com/doc/refman/5.7/en/keywords.html

Comments