Is this a bug in Codeigniter active record?

Viewed 1350

If I used codeigniter active record to fetch data from a db table like this:

$where = array("first_name" => "John", "age <" => 30, "status" => "active");
$this->db->where($where);
$query = $this->db->get("my_table");

die(var_dump($this->db->last_query())); // displays the query string

This code will produce the following query string:

SELECT * FROM (`my_table`) WHERE `first_name` = 'John' AND `age` < 30 AND `status` = 'active'

Now if I assigned a string to $where instead of the array, like this:

$where = "first_name = 'John' AND age < 30 AND status = 'active'";

Then it will produce the following query string:

SELECT * FROM (`my_table`) WHERE `first_name` = 'John' AND age < 30 AND status = 'active'

Notice that when assign a string to $where, codeigniter added backticks (``) only around the first field's name which is first_name in our case. While on the other hand, codeigniter added backticks around all fields names when we assigned an array to $where

My question: Is this a bug in codeigniter or this is normal? And if I used the following code to prevent codeigniter from adding backticks around fields names:

$this->db->where($where, null, false);

Which will produce the following query string:

SELECT * FROM (`my_table`) WHERE first_name = 'John' AND age < 30 AND status = 'active'

Is there any risks or cons of writing where portion this way?

4 Answers
Related