Where Method

The where method purpose is for filtering data from query result by executing WHERE 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 where method from $db property on SENE_Model class.

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


This method has required 2 parameters and 4 optional parameters.


Can contain the name of the column to be filtered. The value of this parameter is auto in escape.


Filter value against the selected column.


The operator value performed for the next WHERE condition, the following values match the value of this parameter.

  • AND
  • OR


The value of the relational operator assigned to the filter condition with the column name.

  • =
  • != or <>
  • >
  • <
  • >=
  • <=
  • like
  • like%
  • %like
  • %like% or like%%
  • notlike
  • notlike%
  • %notlike
  • %notlike% or notlike%%


Add an opening parenthesis at the beginning of the SQL command before the contents of the next WHERE command.


Add a closing parenthesis at the end of the SQL command before the contents of the next WHERE command.


The following is an example of using the where method in the d_order_model.php file.

class D_Order_Model extends SENE_Model{
  var $tbl = 'd_order';
  var $tbl_as = 'dor';

  public function __construct(){

  public function getById($id){
    return $this->db->get_first();
  public function getNotCancelled(){
    return $this->db->get();
  public function getCancelByUser($b_user_id){
    return $this->db->get();
  public function getAllCancelRefund(){
    $this->db->where("is_refund", 1,"OR","=",1,0);
    $this->db->where("is_refund_closed", 1,"OR","=",0,1);
    return $this->db->get();

Generated SQL Command

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

-- result from executing D_Order_Model::getById(112) --
SELECT * FROM `d_order` WHERE `id` = 112;

-- result from executing D_Order_Model::getNotCancelled() --
SELECT * FROM `d_order` WHERE `order_status` != 'cancel';

-- result from executing D_Order_Model::getCancelByUser(2125) --
SELECT * FROM `d_order` WHERE `order_status` LIKE 'cancel' AND `b_user_id` = 2125;

-- result from executing D_Order_Model::getAllCancelRefund() --
SELECT * FROM `d_order` WHERE `order_status` = "order_cancel" AND ( `is_refund` = 1 OR `is_refund_closed` = 1);