Welcome Guest, Not a member yet? Register   Sign In
How to stop quotes getting inserted into my queries


I am trying to get some data from the db with the following 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.


http://ellislab.com/codeigniter/user-gui...tml#select Check the select() docs.

Thanks a lot. Fixed it instantly

Theme © iAndrew 2016 - Forum software by © MyBB