Database Class Object

I have seen people use this piece of code, and I'm trying to understand what it does, because I cannot see it in any coding system or in the source code for the database class.

$this->db->ar_orderby 
+7
source share
4 answers

This is an array that stores column order.

There should be no reason to directly use this property. Instead, call $this->db->order_by('column') , which automatically joins the array.

  • defined in the line system/database/DB_active_rec.php Line 42
  • added to the CI_DB_active_record::order_by method Line 856
  • used to generate SQL in CI_DB_active_record::_compile_select Line 1781
+8
source
+3
source

It still makes sense to use this below:

 if (!count($this->db->ar_orderby)) { $this->db->order_by($this->order_by ); } 

This basically means that if this method is not already set by the db library when calling this method, use this. Prevents the call of "order" twice.

+3
source

You can replace these lines:

 if (!count($this->db->ar_orderby)) { $this->db->order_by($this->order_by ); } 

from:

 if(!count($this->db->order_by($this->order_by))) { $this->db->order_by($this->order_by); } 
0
source

All Articles