Suleman Ahmad
Suleman Ahmad

Reputation: 2103

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.

Upvotes: 0

Views: 5271

Answers (1)

lsl
lsl

Reputation: 4419

 $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

Upvotes: 5

Related Questions