Hi,
today a question that concerns me. Why are not there in the Database class below, in my opinion very useful and often used function?
/* @Function insert_update
*
* Global Function for a Database Entry
* There a distinction between new entry and update.
* All entries are automatically qoutet.
*
* @param table without Suffix
* @param Data as Array
*
*/
function insert_update( $table = NULL , $set = NULL )
{
if (empty($table) || !is_array($set) || !count($set))
{
return FALSE;
}
$this->db->protect_identifiers($table, TRUE);
foreach ($set as $key => $value)
{
// $table . '_date' is always created date
if( $key != $table . '_date' )
{
$update[] = $key." = ".$this->db->escape($value);
}
}
$sql = $this->db->insert_string($table, $set)." ON DUPLICATE KEY UPDATE ".implode(', ', $update);
return $this->db->simple_query($sql);
}