Esempio n. 1
0
 /**
  * 使用insertOnDuplicateKeyUpdate 插入一条记录,插入后不会refresh
  * 
  * @param  array  $data  Column-value pairs.
  * @return mixed         The primary key of the row inserted.
  */
 public static function insertOrUpdateRow(array $data)
 {
     $updateData = array_diff_key($data, array_flip(static::$_primary));
     /**
      * INSERT the new row.
      */
     $tableSpec = (static::$_schema ? static::$_schema . '.' : '') . static::$_name;
     static::$_db->insertOnDuplicateKeyUpdate($tableSpec, $data, $updateData);
     /**
      * Fetch the most recent ID generated by an auto-increment
      * or IDENTITY column, unless the user has specified a value,
      * overriding the auto-increment mechanism.
      */
     if (static::$_sequence === true) {
         /**
          * Zend_Db_Table assumes that if you have a compound primary key
          * and one of the columns in the key uses a sequence,
          * it's the _first_ column in the compound key.
          */
         $pkIdentity = static::$_primary[static::$_identity];
         if (!isset($data[$pkIdentity])) {
             $data[$pkIdentity] = static::$_db->lastInsertId();
         }
     }
     $row = new static($data + static::$_defaultValues, true, false);
     return $row;
 }