Dibi\Connection::insert PHP Method

insert() public method

public insert ( $table, $args ) : dibi\Fluent
return dibi\Fluent
    public function insert($table, $args)
    {
        if ($args instanceof Traversable) {
            $args = iterator_to_array($args);
        } elseif (!is_array($args)) {
            throw new \InvalidArgumentException('Arguments must be array or Traversable.');
        }
        return $this->command()->insert()->into('%n', $table, '(%n)', array_keys($args))->values('%l', $args);
    }

Usage Example

示例#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();
     }
 }
All Usage Examples Of Dibi\Connection::insert