1
votes

How can I escape " (double quotes) with Codeignniter Acitve Record?

$query_string = 'double " quotes';
$sql = "SELECT * FROM name WHERE email LIKE "%'.$query_string.'%" ";
$query = $this->db->query($sql);

I get mysql error

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 '%" OR email like "%"%"

Any suggestions how ti fix that

2
Why don't you use methods from the active record class? $this->db->where() $this->db->like() $this->db->get() - Willem Ellis

2 Answers

2
votes

You can escape any character by putting a \ before it.

So \"

1
votes

Even better, you can bind the parameters!

$query_string = '%double " quotes%';
$sql = "SELECT * FROM name WHERE email LIKE ?";
$query = $this->db->query($sql, array($query_string));