Reputation: 15032
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?
Upvotes: 0
Views: 1972
Reputation: 47883
I don't know what version of CodeIgniter you were using, but the problem no longer exists.
return $this->db
->group_by('X')
->having('Y', 'frontend')
->get('A')
->result();
Will build a rendered SQL string resembling this (with appropriate quoting):
SELECT *
FROM `A`
GROUP BY `X`
HAVING `Y` = 'frontend'
The having()
method calls the protected _wh()
method which the where()
family of methods use as well. The escaping/quoting processes are all consistently baked-in there.
Upvotes: 0
Reputation: 15032
Write the having clause in a such clumsy way:
$this->db->having('A.Y = "frontend"', null, false);
Upvotes: 1