Esempio n. 1
0
 /**
  * {@inheritdoc}
  *
  * @param null $sequence
  * @return integer|string|array
  */
 public function execute($sequence = null)
 {
     $result = Db::query($this->getSQL(), $this->params, $this->types);
     if ($result) {
         return Db::handler()->lastInsertId($sequence);
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * @param array $data
  * @throws Exception
  */
 public function createOne($data)
 {
     try {
         Db::handler()->beginTransaction();
         $data['id'] = reset(parent::createOne($data));
         $this->saveAdditionData($data);
         Db::handler()->commit();
         return $data['id'];
     } catch (\PDOException $e) {
         Db::handler()->rollBack();
         throw $e;
     }
 }
Esempio n. 3
0
 /**
  * Insert new record to table and return last insert Id
  *
  * <code>
  *     Table::insert(['login' => 'Man', 'email' => '*****@*****.**'])
  * </code>
  *
  * @param  array $data Column-value pairs
  * @return string|null Primary key or null
  * @throws Exception\DbException
  */
 public static function insert(array $data)
 {
     $self = static::getInstance();
     $data = $self->filterColumns($data);
     if (!sizeof($data)) {
         throw new DbException("Invalid field names of table `{$self->table}`. Please check use of `insert()` method");
     }
     $table = DbProxy::quoteIdentifier($self->table);
     $sql = "INSERT INTO {$table} SET " . join(',', self::prepareStatement($data));
     $result = DbProxy::query($sql, array_values($data));
     if (!$result) {
         return null;
     }
     /**
      * If a sequence name was not specified for the name parameter, PDO::lastInsertId()
      * returns a string representing the row ID of the last row that was inserted into the database.
      *
      * If a sequence name was specified for the name parameter, PDO::lastInsertId()
      * returns a string representing the last value retrieved from the specified sequence object.
      *
      * If the PDO driver does not support this capability, PDO::lastInsertId() triggers an IM001 SQLSTATE.
      */
     return DbProxy::handler()->lastInsertId($self->sequence);
 }