Skip to content

Instantly share code, notes, and snippets.

@chonthu
Created February 23, 2012 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chonthu/1893489 to your computer and use it in GitHub Desktop.
Save chonthu/1893489 to your computer and use it in GitHub Desktop.
on_duplicate_update 5
<?
class MY_DB_mysqli_driver extends CI_DB_mysqli_driver
{
final public function __construct($params)
{
parent::__construct($params);
}
function _insert_on_duplicate_update($table, $update, $values)
{
foreach($values as $key=>$value)
{
$insert_fields[] = $key.'='.$value;
}
foreach($update as $key=>$name)
{
$update_fields[] = $name.'='.$values['`'.$name.'`'];
}
return "INSERT INTO ".$table." SET ".implode(',', $insert_fields)." ON DUPLICATE KEY UPDATE ".implode(',', $update_fields);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment