Where AS Method

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

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();
  }
}

Parameters

Where 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

$this->db->where(
COLUMN_NAME,
VALUE,
" AND | OR ",
"= | != | <= | >= | < | > | <> |
like | like% | %like | %like% |
notlike | notlike% |%notlike | %notlike%
",
OPENBRACKET,
CLOSEBRACKET
);

COLUMN_NAME

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

VALUE

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

Combining Method

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.

Relational 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.

Escaping 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.