CodeIgniter Forums
active record - simple mysql statement but not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: active record - simple mysql statement but not working (/showthread.php?tid=5186)



active record - simple mysql statement but not working - El Forum - 01-10-2008

[eluser]CI MikeD[/eluser]
Is it something I am missing here? Here is the part of the sql statement built with active record that is getting errors:

Quote:$this->db->where('DATE_ADD(CURRENT_DATE,INTERVAL 1 DAY)', 'ending');

CI returnes this error: An Error Was Encountered, Error Number: 1064

with this created part of mysql:
Code:
DATE_ADD(CURRENT_DATE,INTERVAL 1 DAY) 'ending'

So it fails to create equal sign (=). If I force the creation of = sign like this:
Quote:$this->db->where('DATE_ADD(CURRENT_DATE,INTERVAL 1 DAY)=', 'ending');

the error is the same event though query looks ok now. The most "funny" thing about all this is while CI reports error when i copy paste entire generated mysql to phpmyadmin it works.

above is only part of mysql query. any ideas?thanks.


active record - simple mysql statement but not working - El Forum - 01-10-2008

[eluser]xwero[/eluser]
isn't the where statement
Code:
$this->db->where(‘ending’,’DATE_ADD(CURRENT_DATE,INTERVAL 1 DAY)’);
I guess the ending is a field name, or not?


active record - simple mysql statement but not working - El Forum - 01-10-2008

[eluser]CI MikeD[/eluser]
xwero,thank you very much! yes, ending is filed name.I see no error now.I think that was it Smile


active record - simple mysql statement but not working - El Forum - 01-11-2008

[eluser]CI MikeD[/eluser]
eh,the joy was shortlived. Above statement produces
Code:
ending = 'DATE_ADD(CURRENT_DATE,INTERVAL 1 DAY)'
but it should be
Code:
ending = DATE_ADD(CURRENT_DATE,INTERVAL 1 DAY)
, without simple quotes. I checked some thread and some people have simmilar problems. So there is no way (i do not want to write helpers or modify CI code) active record can produce this without active record adding single quotes? It would be "shame" to not use active record for such a small issue,i really like it Smile

Or did i miss something?


active record - simple mysql statement but not working - El Forum - 01-11-2008

[eluser]xwero[/eluser]
There is an upcomming change in the SVN where the set method has a third argument that can be set to false to not automatically escape the values. I think it's useful for the where method too, like your example proves.

But for now i think you have to settle for the basic query method.


active record - simple mysql statement but not working - El Forum - 01-11-2008

[eluser]CI MikeD[/eluser]
thanks again xwero!