- Seme Framework
- Credits
- Version 3.1.5
- Issue
- Deployment
Update Method
The update
is part of Query Builder method for executing SQL UPDATE
command.
Basic Usage
Here is the basic usage update
method from $db
property on SENE_Model class.
$this->db->update(string $table_name, array $data_update [, bool $is_debug=0]): bool
Parameters
This method has 2 required parameters and 1 optional parameter.
$table_name
The $table_name
refers to the name of the table to which the data is to be updated.
$data_update
The $data_update
value can contain key value pair in array and automatically escaped
.
The key refer to column name of the table and the value refer to value that will be inserted.
This value supported MySQL builtin functions and values, such as:
NOW()
NULL
$is_debug
The $is_debug
parameter is a marker (flag) to enable debug mode.
The value of this parameter can be filled with int 1
to enable debug mode and display the query to be processed.
Fill it with another value to not enable debug mode.
In debug mode, there will be no query execution process to the database system.
Example usage
Here is the source code examples for a model using update
method.
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);
}
}
Controller class example
And then this is controller class example using the model class example
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';
}
}
}