phpcodeigniteractiverecordquery-builderhaving

Value quoting isn't applied when calling CodeIgniter's having() method


I have a problem with Code Igniter having clause.

I need to produce the following SQL with active record:

SELECT *
FROM A
GROUP BY A.X
HAVING A.Y = 'test'

But using the following code:

$this->db->select('*');
$this->db->from('A');
$this->db->group_by('A.X');
$this->db->having('A.Y','frontend');

Produces:

SELECT *
FROM A
GROUP BY A.X
HAVING A.Y = test

And it seems impossible to escape the string value... Or is it?


Solution

  • Write the having clause in a such clumsy way:

    $this->db->having('A.Y = "frontend"', null, false);