Showing posts with label clone. Show all posts
Showing posts with label clone. Show all posts

Monday, February 15, 2016

Menyalin atau klon data dalam MySQL dengan CodeIgniter

Tajuk dalam BI 'How To Clone a Row in MySQL Using Codeigniter?'.

function DuplicateMySQLRecord ($table, $primary_key_field, $primary_key_val)
{
/* generate the select query */
$this->db->where($primary_key_field, $primary_key_val);
$query = $this->db->get($table);

foreach ($query->result() as $row){
foreach($row as $key=>$val){
if($key != $primary_key_field){
/* $this->db->set can be used instead of passing a data array directly to the insert or update functions */
$this->db->set($key, $val);
}//endif
}//endforeach
}//endforeach

/* insert the new record into table*/
return $this->db->insert($table);
}

 

Sumber: http://developer-paradize.blogspot.my/2015/01/how-to-clone-row-in-mysql-using.html
Share: