Update Method

Update method is part of database class builder for updating a table.

Parameters

Update 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->update(string $table_name, array $data_update, [bool $is_debug=0]): bool

$data_update

Data update 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 edit title 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 update($id,$du){
    $this->db->where("id",$id);
    $this->db->update($ths->tbl,$du);
  }
}

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;
    $du = array();
    $du['title'] = "This is new title of this blog!";
    $res = $this->bm->update($id,$du); //call the method on the model
    if($res){
      echo 'Success';
    }else{
      echo 'failed';
    }
  }
}