Where AS Method

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

Basic Usage

$this->db->where(string $column_name, mixed $filter_value [, string $operator = 'AND' [, string $relation_operator = '=' [, int $open_bracket = 0 [, int $close_bracket = 0 ]]]]): $this->db

The where_as method is part of database class builder for filtering data compatible with WHERE Clause on SQL. This method support chained, and has flow from top to bottom while bracket are used. The difference is this method does not automatically escaped

Parameters

Where AS method has 2 required parameters that is column name and value, another parameters are optional. Here is the completed parameters can be used by where methods

$column_name

Column name required for filtering data from table. The columname should exist on selected table. This method has unescaped value.

$filter_value

Value required for matched with data on table. This method has unescaped value.

$operator

Default value is AND, this parameter useful for filtering data for multiple condition. Available value AND or OR. Value of this parameter is not case sensitive.

$relation_operator

Value required for matched $column_name with value. Available value:

  • =
  • <
  • >
  • <=
  • >=
  • <>
  • like
  • like%
  • %like
  • %like%
  • notlike
  • notlike%
  • %notlike
  • %notlike%

Value of this parameter is not case sensitive.

$open_bracket

Required for adding bracket for prioritize condition filtering, default value 0. Available value 1 and 0.

$close_bracket

Required for adding bracket for prioritize condition filtering, default value 0. Available value 1 and 0.

Example

Here is the basic example using where_as method in a model class.

class Blog_Model extends SENE_Model{
  var $tbl = 'd_order';
  var $tbl_as = 'dor';
  var $tbl2 = 'b_user';
  var $tbl2_as = 'bu';
  public function __construct(){
    parent::__construct();
    $this->db->from($this->tbl,$this->tbl_as);
  }
  public function getNow($id){
    $this->db->select("$this->tbl2_as.fname",'fname',0);
    $this->db->select("$this->tbl_as.date_order",'date_order',0);
    $this->db->join($this->tbl2,$this->tbl2_as,'id',$this->tbl_as,'b_user_id','');
    $this->db->where_as("DATE($this->tbl_as.date_order)","CURRENT_DATE()","AND","=",0,0);
    return $this->db->get();
  }
  public function getYesterday($b_user_id){
    $this->db->select("$this->tbl_as.*, $this-tbl_as.status_text",'status_text',0);
    $this->db->select("$this->tbl2_as.fname",'fname',0);
    $this->db->select("$this->tbl2_as.email",'email',0);
    $this->db->where_as("$this->tbl_as.status_text",$this->db->esc("order_invoice"),"AND","=",0,0);
    $this->db->where_as("DATE(date_order)","DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)","AND","=",0,0);
    return $this->db->get();
  }
}

Escaping The Value

Escaping value is required for string matching. Here is the example

$this->db->where_as("$this->tbl_as.status_text",$this->db->esc("order_completed"));

Basic Where Condition

For basic usage, Seme Framework has basic where method called where method.