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/1893486 to your computer and use it in GitHub Desktop.
Save chonthu/1893486 to your computer and use it in GitHub Desktop.
on_duplicate_update 4
<?
class MY_DB_active_record extends CI_DB_active_record
{
function on_duplicate_update($table = '',$fields = NULL,$set = NULL)
{
if ( ! is_null($set))
{
$this->set($set);
}
if (count($this->ar_set) == 0)
{
if ($this->db_debug)
{
return $this->display_error('db_must_use_set');
}
return FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
if ($this->db_debug)
{
return $this->display_error('db_must_set_table');
}
return FALSE;
}
$table = $this->ar_from[0];
}
$sql = $this->_insert_on_duplicate_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $this->ar_set);
$this->_reset_write();
return $this->query($sql);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment