CodeIgniter Forums
How to stop quotes getting inserted into my queries - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How to stop quotes getting inserted into my queries (/thread-49363.html)



How to stop quotes getting inserted into my queries - El Forum - 02-16-2012

[eluser]Durkin[/eluser]
Hi,

I am trying to get some data from the db with the following code:

Code:
// Code below returns all books, and listing data if available - Removes already bought books
    $this->db->select('*, COUNT(CASE WHEN (lb.locked = 0 || lb.modified_time < DATE_SUB(NOW(),INTERVAL 15 MINUTE)) && lb.bought = 0 THEN 1 ELSE NULL END) as Quantity, b.id as book_id, c.id as course_id')->from('Courses as c');
    //$this->db->select('*, COUNT(lb.Listed_Books_ID) as Quantity')->from('Books as b');
    $this->db->join('Books_courses as bc', 'c.id = bc.course_id');
    $this->db->join('Books as b', 'bc.book_id = b.id');
    $this->db->join('Listed_Books as lb', 'lb.Book_ID = b.id', 'LEFT OUTER');
    $this->db->group_by(array("lb.Book_ID", "lb.Condition", "c.id"));

Problem is that I am getting an SQL error due to active record placing quotes around the word 'INTERVAL'. If I run the query that is outputted with the error on my database, without the quotes, it runs fine. How can I stop these quotes appearing in the query? It seems to add them correctly in every other instance, not sure why it is adding them incorrectly now.

Thanks


How to stop quotes getting inserted into my queries - El Forum - 02-16-2012

[eluser]Aken[/eluser]
http://ellislab.com/codeigniter/user-guide/database/active_record.html#select Check the select() docs.


How to stop quotes getting inserted into my queries - El Forum - 02-16-2012

[eluser]Durkin[/eluser]
Thanks a lot. Fixed it instantly