MJ Convento MJ Convento - 1 month ago 6
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

I don't understand why people never use backticks!

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