MJ Convento MJ Convento - 10 months ago 40
PHP Question

How do I insert a record in SQL with reserved word "from"?

I am using CodeIgniter and I've noticed that one of our fields is named "from" because the table is for saving emails. So someone used "from" which is a reserved word from database.

I've used

$this->db->query("INSERT INTO email_setting (client_id, [from], created_by) VALUES (9251 , 'mjmsample@gmail.com', 1)")

I've also tried these codes

$this->db->query("INSERT INTO email_setting e (e.client_id, e.from, e.created_by) VALUES (9251 , 'mjmsample@gmail.com', 1)")

$this->db->query("INSERT INTO email_setting ('client_id', 'from', 'created_by') VALUES (9251 , 'mjmsample@gmail.com', 1)")

All of these but no luck, is there any workaround this?

Answer Source

I don't understand why people never use backticks!

INSERT INTO `email_setting` `e` (`e`.`client_id`, `e`.`from`, `e`.`created_by`)