phpmysqlcodeignitercodeigniter-3corruption

CodeIgniter 3.0.0 and 3.0.1 Bug: When where() value contains "and", the rendered query is corrupted


What's up with this logic:

I have a book title called "Day and Night"

$this->db->select('b.Book_Name,Author');
$this->db->from('Books b');
$this->db->where('Book_Name',$book['Book_Name']);
$query = $this->db->get();

if($query->num_rows() > 0 ) 
    {
     $arr['by_genre'] = $query->result_array();
    }

0 results,

however if I change the name to "Day an Night" I get

  ['Book_Name'=>'Day an Night', 
     'Author'=>'Gene Night',  
     'ISBN'=> '124BA123', ..]

so my question is how do i tell my query to escape the "and" treating it as a string and not a condition.


Solution

  • This is a bug in CodeIgniter 3.0.0 and 3.0.1. It was fixed in version 3.0.2, and the current stable version is 3.0.3 ...

    All you need to do is update your CI setup.