insert() public method

public insert ( $table, $args ) : dibi\Fluent
return dibi\Fluent
Ejemplo n.º 1
0
 /**
  * Adds new user.
  * @param  string
  * @param  string
  * @param  string
  * @return void
  * @throws DuplicateNameException
  */
 public function add($username, $password, $role = 'guest')
 {
     try {
         $this->db->insert(self::TABLE_NAME, [self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => Passwords::hash($password), self::COLUMN_ROLE => $role])->execute();
     } catch (Nette\Database\UniqueConstraintViolationException $e) {
         throw new DuplicateNameException();
     }
 }
Ejemplo n.º 2
0
 /**
  * @param array $data
  * @return int
  */
 public function add($data)
 {
     $this->database->insert($this->table, $data)->execute();
     try {
         return $this->database->insertId;
     } catch (Dibi\Exception $e) {
         return NULL;
     }
 }
Ejemplo n.º 3
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;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * @param $name
  * @param $params
  */
 public function saveContent($name, $params)
 {
     $names = $this->decodeNames($name);
     $locale = isset($params->locale) ? $params->locale : '';
     $rowId = $this->connection->select('id')->from(self::TABLE)->where(['namespace' => $names->namespace, 'name' => $names->name, 'locale' => $locale])->fetchSingle();
     $content = isset($params->content) ? $params->content : '';
     if ($rowId) {
         // update
         $this->connection->update(self::TABLE, ['content' => $content])->where(['id' => $rowId])->execute();
     } else {
         // new
         $this->connection->insert(self::TABLE, ['namespace' => $names->namespace, 'name' => $names->name, 'locale' => $locale, 'content' => $content])->execute();
     }
     $this->findContentAndFillCache($names->namespace, '', '');
 }
Ejemplo n.º 5
0
 public function log(AbstractMigration $migration, $timestamp)
 {
     $datetime = new \DateTime();
     $this->connection->insert($this->table, ['version' => $migration->getVersion(), 'executed' => $datetime->setTimestamp($timestamp)])->execute();
 }