Esc Method

The esc method is used to process escape character while value passed Query Builder and will execute the PHP MySQLi command::real_escape_string .

Basic Usage

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

$this->db->esc(mixed $val): mixed

Parameters

The esc method required only 1 parameter, it is $val.

$val

Can contain int or string to be escaped.

Example

Here is the example for esc method on d_order_model.php file.

<?php
class D_Order_Model extends SENE_Model{
  var $tbl = 'd_order';
  var $tbl_as = 'dor';
  var $tbl2 = 'd_order_detail';
  var $tbl2_as = 'dod';

  public function __construct(){
    parent::__construct();
    $this->db->from($this->tbl,$this->tbl_as);
  }
  public function getByKode($kode){
    $this->db->from($this->tbl,$this->tbl_as);
    $this->db->join($this->tbl2, $this->tbl2_as, 'id', $this->tbl_as, 'd_order_id', '');
    $this->db->where_as("$this->tbl_as.kode", $this->db->esc($kode));
    return $this->db->get();
  }
  ...
}

SQL Result

The following is the SQL command that generated from D_Order_Model class methods.

-- result from executing D_Order_Model::getByKode('KN210803001') --
SELECT * FROM `d_order` WHERE `kode` = "KN210803001";