getInsertID() публичный Метод

См. также: Adapter::getInsertID
public getInsertID ( )
Пример #1
0
 /**
  * Inserts a record into the database using a series of insert columns
  * and corresponding insertvalues. Returns the insert id.
  *
  * @param string $table         table to perform query on
  * @param array  $insertcolumns columns to be inserted
  * @param array  $insertvalues  values to be inserted
  *
  * @return integer
  */
 protected function insertRecord($type, $insertcolumns, $insertvalues)
 {
     $default = $this->defaultValue;
     $suffix = $this->getInsertSuffix($type);
     $table = $this->esc($type);
     if (count($insertvalues) > 0 && is_array($insertvalues[0]) && count($insertvalues[0]) > 0) {
         $insertSlots = array();
         foreach ($insertcolumns as $k => $v) {
             $insertcolumns[$k] = $this->esc($v);
             if (isset(self::$sqlFilters['w'][$type][$v])) {
                 $insertSlots[] = self::$sqlFilters['w'][$type][$v];
             } else {
                 $insertSlots[] = '?';
             }
         }
         $insertSQL = "INSERT INTO {$table} ( id, " . implode(',', $insertcolumns) . " ) VALUES\n\t\t\t( {$default}, " . implode(',', $insertSlots) . " ) {$suffix}";
         $ids = array();
         foreach ($insertvalues as $i => $insertvalue) {
             $ids[] = $this->adapter->getCell($insertSQL, $insertvalue, $i);
         }
         $result = count($ids) === 1 ? array_pop($ids) : $ids;
     } else {
         $result = $this->adapter->getCell("INSERT INTO {$table} (id) VALUES({$default}) {$suffix}");
     }
     if ($suffix) {
         return $result;
     }
     $last_id = $this->adapter->getInsertID();
     return $last_id;
 }
Пример #2
0
 /**
  * Returns the insert ID for databases that support/require this
  * functionality. Alias for R::getAdapter()->getInsertID().
  *
  * @return mixed
  */
 public static function getInsertID()
 {
     return self::$adapter->getInsertID();
 }