Get First Method

Get First method is part of database class builder for filtering just only one result.

Parameters

Group By method has 2 parameter

$this->db->get_first([string $result_type, [bool $is_debug]]): mixed

$result_type

Result type consist of array and object, if value has "array" the result will be array otherwise will returned object.

Example usage

Here is the examples using select method. See the first of this page for full example.

Basic Usage

For example we assumed want to add new data in blog table. First, in the model:

class Blog_Model extends SENE_Model{
  var $tbl = 'blog';
  var $tbl_as = 'b';
  public function __construct(){
	 parent::__construct();
  }
  public function getById($id){
    $this->db->select("id");
    $this->db->select("title");
    $this->db->select("content");
    $this->db->from($this->tbl,$this->tbl_as);
    $this->db->where_as("id",$id);
    return $this->db->get_first();
  }
  public function getByIdArray($id){
    $this->db->select("id");
    $this->db->select("title");
    $this->db->select("content");
    $this->db->from($this->tbl,$this->tbl_as);
    $this->db->where_as("id",$id);
    return $this->db->get_first('array');
  }
  public function getByIdArrayDebugQuery($id){
    $this->db->select("id");
    $this->db->select("title");
    $this->db->select("content");
    $this->db->from($this->tbl,$this->tbl_as);
    $this->db->where_as("id",$id);
    return $this->db->get_first('array',1);
  }
}