EllisLab text mark
Advanced Search
     
Database Class Question
Posted: 28 July 2011 05:12 PM   [ Ignore ]
Joined: 2011-07-24
5 posts

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($tableTRUE);

    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);
 
Posted: 29 July 2011 12:38 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-04-15
454 posts

chewbacca,

1) English only here, please (or the best translation you can manage with your original text)

2) I’m not sure of the official reason why it is left out, but ON DUPLICATE KEY UPDATE is a mysql function, and Database Class should be vendor neutral, would be my quick guess.

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?

 
Posted: 29 July 2011 02:53 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2011-07-24
5 posts

to 1) I’m sorry I sometimes write in my native language. Otherwise I will loose them still. smile
to 2 )If I am right you’re right. But that’s what the MySQL driver classes.