Dibi\Connection::insertId PHP Méthode

insertId() public méthode

Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().
public insertId ( $sequence = NULL ) : integer
Résultat integer
    public function insertId($sequence = NULL)
    {
        return $this->getInsertId($sequence);
    }

Usage Example

Exemple #1
0
 /**
  * @param $item
  * @return \Dibi\Result|int
  */
 public function save($item)
 {
     if ($item->{$this->primaryKey}() === NULL) {
         $data = $this->itemToArray($item);
         try {
             $this->db->insert($this->tableName, $data)->execute();
             return $this->db->insertId();
         } catch (Exception $e) {
             Debugger::log(printf("An error has occurred: %s\n", $e->getMessage()), ILogger::ERROR);
             return NULL;
         }
     } else {
         $data = $this->itemToArray($item);
         try {
             $this->db->update($this->tableName, $data)->where($this->primaryKey . ' = %i', $item->{$this->primaryKey}())->execute();
             return $item->{$this->primaryKey}();
         } catch (ForeignKeyConstraintViolationException $e) {
             Debugger::log($e->getMessage(), ILogger::ERROR);
             return NULL;
         }
     }
 }