Exemple #1
0
 /**
  * Insert an array of values into the database table and return the ID.
  *
  * @param  array   $values
  * @param  string  $column
  * @return int
  */
 public function insert_get_id($values, $column = 'id')
 {
     $sql = $this->grammar->insert_get_id($this, $values, $column);
     $result = $this->connection->query($sql, array_values($values));
     if ($this->grammar instanceof Postgres) {
         return (int) $result[0]->{$column};
     } else {
         return (int) $this->connection->pdo->lastInsertId();
     }
 }
Exemple #2
0
 /**
  * Insert an array of values into the database table and return the key.
  *
  * @param  array   $values
  * @param  string  $column
  * @return mixed
  */
 public function insert_get_id($values, $column = 'id')
 {
     $sql = $this->grammar->insert_get_id($this, $values, $column);
     $result = $this->connection->query($sql, array_values($values));
     // If the key is not auto-incrementing, we will just return the inserted value
     if (isset($values[$column])) {
         return $values[$column];
     } else {
         if ($this->grammar instanceof Postgres) {
             return (int) $result[0]->{$column};
         } else {
             return (int) $this->connection->pdo->lastInsertId();
         }
     }
 }