update() 공개 메소드

Create a update statement
public update ( array $columns = null ) : Update
$columns array
리턴 Pop\Db\Sql\Update
예제 #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();
 }
예제 #2
0
 public function testUpdate()
 {
     $s = new Sql(Db::factory('Sqlite', array('database' => __DIR__ . '/../tmp/test.sqlite')), 'users');
     $s->update(array('username' => 'newuser'))->orderBy('id')->limit(1);
     $this->assertEquals('UPDATE "users" SET "username" = \'newuser\' ORDER BY "id" ASC LIMIT 1', $s->render(true));
 }