Exec Method

The exec method is used for executing raw SQL against the table.

Basic Usage

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

$this->db->exec(string $sql): boolean


This method has 1 required parameter.


The $sql value can be a completed single command of SQL.


Here is the example for exec method in a model class.

class C_Produk_Model extends SENE_Model {
  var $tbl = 'c_produk';
  var $tbl_as = 'cp';

  public function __construct(){
  public function unpublishOldProduct($id){
    $sql = 'UPDATE '.$this->tbl.' SET is_published = 0 WHERE DATE(date_created) < DATE("2019-01-01")';
    return $this->db->exec($sql);


This method only suitable for executing query that contains INSERT, UPDATE, DELETE, TRUNCATE, DROP, and another DDL operation.

Please use Query Method for collecting the result from raw SQL.