Select AS Method
Select AS method is part of database class builder for selecting column data into a table with aliases.
Parameters
Update method has 3 required parameters that is column name and value, another parameters are optional. Here is the completed parameters can be used by where methods
$this->db->select_as(string $column_name_or_function, string $alias, bool $force_escape): dbObject
$column_name_or_function
Column Name can be single column name, or can be filled with wildcard "*", or can be filled with MySQL function.
$alias
Alias Aliased name of $column_name_or_function.
$force_escape
Boolean Flag Force escape the column name. optional.
Example usage
Here is the examples using select_as 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 countList(){ $this->db->select_as("COUNT(*)","total",0); $this->db->from($this->tbl,$this->tbl_as); return $this->db->get_first(); } public function translated($id){ $this->db->select("id","blog_id",0); $this->db->select("title","judul",0); $this->db->select("content","isi",0); $this->db->from($this->tbl,$this->tbl_as); $this->db->where_as("id",$id); return $this->db->get_first(); } public function allButModified($id){ $this->db->select("$this->tbl_as.*, id","blog_id",0); $this->db->from($this->tbl,$this->tbl_as); $this->db->where_as("id",$id); return $this->db->get_first(); } }
at the controller, we assumed has file named blog.php
class Blog extends Sene_Controller{ public function __construct(){ parent::__construct(); $this->load('blog_model','bm'); #class scope model } public function index(){ $blogs = $this->bm->countList(); $this->debug($blogs); } public function detail($id){ $blog = $this->bm->translated($id); $this->debug($blog); } public function all($id){ $blog = $this->bm->allButModified($id); $this->debug($blog); } }