Insert Method

Insert method is part of database class builder for inserting data into a table.

Parameters

Insert method has 2 required parameters that is table name and values in key value format.

$this->db->insert(string $table_name, array $data_insert, [bool $is_multiple=0], [bool $is_debug=0]): bool

$data_insert

Data insert is key value pair in an array. The key refer to column name of the table.

Example usage

Here is the examples using insert method. See the first of this page for full example.

Basic Usage

For example we assumed want to add new data in blog table. First, in the model:

class Blog_Model extends SENE_Model{
  var $tbl = 'blog';
  var $tbl_as = 'b';
  public function __construct(){
	 parent::__construct();
  }
  public function insert($di){
    $this->db->insert($ths->tbl,$di);
  }
}

at the controller, we assumed has file named blog.php

class Blog extends Sene_Controller{
  public function __construct(){
    parent::__construct();
    $this->load('blog_model','bm'); #class scope model
  }
  public function index(){
    $id = 1;
    $di = array();
    $di['id'] = 1;
    $di['title'] = "This is new title of this blog!";
    $di['content'] = "This is new title of this blog!";
    $res = $this->bm->insert($id,$di); //call the method on the model
    if($res){
      echo 'Success';
    }else{
      echo 'failed';
    }
  }
}