简体   繁体   中英

How to remove single quotes that is automatically inserted in codeigniter?

How to prevent in codeigniter to not insert single quotes around in our query?

When we write query in codeigniter it inserts automatically single quotes, like this:

 $this->db->select('id, ifnull(name,\'\') as name');
 $this->db->from('table');

which creates database error.

 $this->db->select('id, ifnull("name",\'\') as name', false);
 $this->db->from('table');

Is what you're after. The quotes are escaping to stop sql injection, be sure not to mix unsanitized input from the user.

I guess I should also note that using this false parameter will stop double quote encapsulation, if you're using postgres you'll probably need to encapsulate any kew words used as column names yourself. (see difference between name and "name" )

Active Record - Selecting Data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM