active record class in codeigniter (Update)
<?php
/************* Updating Data ************************/
//Generates an update string and runs the query based on the data
// One can pass an array or an object to the function
$data = array(
'title' => $title,
'name' => $name,
'date' => $date
);
$this -> db -> where('id', $id);
$this -> db -> update('tablename', $data);
// By Using an object:
class Myclass {
var $title = 'My Title';
var $content = 'My Content';
var $date = 'My Date';
}
$object = new Myclass;
$this -> db -> where('id', $id);
$this -> db -> update('mytable', $object);
// The use of the $this->db->where() function, enabling you to set the WHERE clause.
// One can optionally pass this information directly into the update function as a string:
$this -> db -> update('tablename', $data, "id = 4");
// Using an array:
$this -> db -> update('tablename', $data, array('id' => $id));
// One may also use the $this->db->set() function described above when performing updates.
$this -> db -> update_batch();
// Generates an update string based on the data you supply, and runs the query.
//You can either pass an array or an object to the function
$data = array(
array(
'title' => 'My title' ,
'name' => 'My Name 2' ,
'date' => 'My date 2'
),
array(
'title' => 'Another title' ,
'name' => 'Another Name 2' ,
'date' => 'Another date 2'
)
);
$this -> db -> update_batch('mytable', $data, 'title');
//The first parameter will contain the table name,
//the second is an associative array of values,
//the third parameter is the where key.
Comments
Post a Comment