ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Database Class Question

July 28, 2011 5:12pm

Subscribe [1]
  • #1 / Jul 28, 2011 5:12pm

    chewbacca

    3 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($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);
    }
  • #2 / Jul 29, 2011 12:38am

    jmadsen

    438 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.

  • #3 / Jul 29, 2011 2:53am

    chewbacca

    3 posts

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

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases