Pop\Db\Sql::update PHP Method

update() public method

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

Usage Example

Exemplo n.º 1
0
 /**
  * Method to save a value to cache.
  *
  * @param  string $id
  * @param  mixed  $value
  * @param  string $time
  * @return void
  */
 public function save($id, $value, $time)
 {
     $time = time() + (int) $time;
     // Determine if the value already exists.
     $this->sqlite->select()->where()->equalTo('id', ':id');
     $this->sqlite->adapter()->prepare($this->sqlite->render(true))->bindParams(array('id' => sha1($id)))->execute();
     $rows = array();
     while (($row = $this->sqlite->adapter()->fetchResult()) != false) {
         $rows[] = $row;
     }
     // If the value exists, update it.
     if (count($rows) > 0) {
         $this->sqlite->update(array('value' => ':value', 'time' => ':time'))->where()->equalTo('id', ':id');
         $params = array('value' => serialize($value), 'time' => $time, 'id' => sha1($id));
         // Else, save the new value.
     } else {
         $this->sqlite->insert(array('id' => ':id', 'value' => ':value', 'time' => ':time'));
         $params = array('id' => sha1($id), 'value' => serialize($value), 'time' => $time);
     }
     $this->sqlite->adapter()->prepare($this->sqlite->render(true))->bindParams($params)->execute();
 }
All Usage Examples Of Pop\Db\Sql::update