Pop\Db\Sql::insert PHP Method

insert() public method

Create a insert statement
public insert ( array $columns = null ) : Insert
$columns array
return Pop\Db\Sql\Insert
    public function insert(array $columns = null)
    {
        if (null === $this->clause || !$this->clause instanceof \Pop\Db\Sql\Insert) {
            if (null === $columns) {
                throw new Exception('Error: The columns parameter cannot be null for a new INSERT clause.');
            }
            $this->clause = new Sql\Insert($this, $columns);
        }
        return $this->clause;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Write to the log
  *
  * @param  array $logEntry
  * @return Db
  */
 public function writeLog(array $logEntry)
 {
     $columns = [];
     $params = [];
     $i = 1;
     foreach ($logEntry as $column => $value) {
         $placeholder = $this->sql->getPlaceholder();
         if ($placeholder == ':') {
             $placeholder .= $column;
         } else {
             if ($placeholder == '$') {
                 $placeholder .= $i;
             }
         }
         $columns[$column] = $placeholder;
         $params[$column] = $value;
         $i++;
     }
     $this->sql->insert($columns);
     $this->sql->db()->prepare((string) $this->sql)->bindParams($params)->execute();
     return $this;
 }
All Usage Examples Of Pop\Db\Sql::insert