Codeigniter query builder class results Codeigniter query builder class results codeigniter codeigniter

Codeigniter query builder class results


No. Not really.You can, however, control what the model returns. Keep in mind that an empty resultset, for example, is not necessarily a "failed" query. There's a lot of use cases where an empty resultset may be a good thing.

After actually running the query you will get an object with the result

for instance, when selecting, you can do $result = $this->db->get() and your $result variable will become an object with a lot of information you can access:

Number of returned rows: $result->num_rows();Returned contents: $result->result();Specific rows: $result->row(0);Specific field in a specific row: $result->row(3)->field_name;

When inserting or updating, $this->db->affected_rows() becomes available so you can check how many rows were updated or inserted. Inserts also make $this->db->insert_id() available in case you need the table's primary key value for the row you inserted.

Thus, you are in control of the logic.

when selecting, I usually do:

$query = $this->db->get();if ($query->num_rows() == 0){  return false;}else{  return $query->row(0);}

Then I check, in the controller, if the model returned false or a real resultset (sometimes I just return true instead of the actual resultset if I'm just checking for something to exist). You can tailor the results to your needs.

When inserting, I usually check:

if ($this->db->affected_rows() != 0){  return $this->db->insert_id();}else{  return false;}

(in the controller, a false being returned would be handled as an "insertion failed").

To answer your question more globally: No, nothing really happens by default, but Codeigniter gives you everything you need to tailor the behavior of your site to your specific needs and tastes