get() public method

Compiles the select statement based on the other functions called and runs the query
public get ( $table = '', $limit = null, $offset = null ) : object
return object
Ejemplo n.º 1
0
 /**
  * 批量读取数据
  * @param array|string $where 条件
  * @param string $order 排序字段
  * @param int $limit 查询数量
  * @param int $offset 查询起始偏移量
  * @return array
  */
 public function fetchAll($cols = '*', $where, $order, $limit = NULL, $offset = NULL)
 {
     $this->db->select($cols);
     $this->where($where);
     if (!empty($order)) {
         $this->db->order_by($order);
     }
     return $this->db->get($this->_name, $limit, $offset)->result_array();
 }
Ejemplo n.º 2
0
 /**
  * Load a record, by a specific ID, and by any attributes specified
  *
  * @param mixed $ID
  * @return bool
  */
 public function load($ID = null)
 {
     if (is_object($ID)) {
         //Used by load many to initialise new objects
         //If it this object, or a fancy join?
         if (is_a($ID, 'stdClass')) {
             //This is just to strip from
             $this->_strip_row($ID);
             return true;
         } else {
             //Passed an object to load with
             $this->related($ID);
         }
     }
     //Did the user reauest via a specific ID?
     if (is_numeric($ID) or $ID === 0) {
         $this->db->where($this->_id(), $ID);
     }
     //Load in custom SQL
     //$this->_generate_related_sql_old();
     $this->_generate_related_sql();
     //Are there any variabloes set in the object to be used in the query?
     foreach ($this->_data as $Field => $Value) {
         $this->db->where($this->_table() . '.' . $Field, $Value);
     }
     $this->_data = array();
     $this->db->select($this->_table() . '.*');
     $this->db->from($this->_table());
     $Query = $this->db->get();
     if ($Query->num_rows() == 1) {
         $this->_strip_row($Query->row());
         return true;
     } else {
         return false;
     }
 }