Majed DH
Majed DH

Reputation: 119

calling database date functions in codeigniter

I'm using having function in code igniter active record but it produces wrong results.

$this->db->having('y', 'year('.$date.')');

produces :

`y` =  'year(2014-2-1)'

and this:

$this->db->having('y', 'year('.$date.')',true);

is only escaping the name of the column so it produces:

 y = year('2014-2-1')

but i want to produce this:

`y` = year('2014-2-1')

or this

 `y` = year(2014-2-1)

Upvotes: 2

Views: 59

Answers (1)

M Khalid Junaid
M Khalid Junaid

Reputation: 64466

According to active record documentation you can do so,pass third parameter as FALSE so column will be protected for adding back-ticks and you can add back-ticks manually

$this->db->having("`y` = YEAR('".$date."')",null,FALSE);

Upvotes: 1

Related Questions