Select Method

The select method purpose is for filtering data from query result by executing SELECT SQL command. This method will put the result SQL command on Query Builder can combined with another Query Builder methods.

Basic Usage

Here is the basic usage select method from $db property on SENE_Model class.

$this->db->select(string $column_name): $this->db

Parameters

This method has 1 required parameters.

$column_name

The $column_name value can be a single column name of table or can fill with * (wildcard) for selecting all columns.

Example

Here is the examples using select method in a model class.

class D_Blog_Model extends SENE_Model{
  var $tbl = 'd_blog';
  var $tbl_as = 'b';
  public function __construct(){
    parent::__construct();
  }
  public function getList(){
    $this->db->select("*");
    $this->db->from($this->tbl,$this->tbl_as);
    return $this->db->get();
  }
  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();
  }
}

Generated SQL Command

The following is the SQL command generated by the method in the D_Blog_Model class example.

-- result from executing D_Blog_Model::getList() --
SELECT * FROM `d_blog`;

-- result from executing D_Blog_Model::getById(53) --
SELECT `id`, `title`, `content` FROM `d_order` WHERE `id` = 53;