Пример #1
0
 public static function select($table, $condition)
 {
     $query = DBQuery::select($table);
     $query = self::applyCondition($query, $condition);
     $result = $query->act();
     if (!is_array($condition)) {
         // returning object if [int $id]
         return $result->fetch();
     } else {
         // returning DBResult otherwise
         return $result;
     }
 }
Пример #2
0
 public function toggleStatus($id)
 {
     $params = array();
     $query = new DBQuery();
     $query->select('validado');
     $query->from($this->table);
     $query->where($this->identifier . ' = ' . (int) $id);
     $status = (bool) DB::getInstance()->getValue($query);
     $status = !$status;
     $params['validado'] = (int) $status;
     return DB::getInstance()->update($this->table, $params, $this->identifier . ' = ' . (int) $id);
 }
Пример #3
0
 /**
  * Tests act()
  * 
  * @test
  */
 public function testAct()
 {
     // inserting
     $inserted_id = DBQuery::insert('tests')->set('foo', 'bar', 'bar', 'foo')->act();
     $this->assertSame(mysql_insert_id(), $inserted_id);
     // selecting
     $foo = DBQuery::select('tests')->where('id', $inserted_id)->act()->fetch();
     $this->assertEquals($inserted_id, $foo->id);
     $this->assertEquals('bar', $foo->foo);
     $this->assertEquals('foo', $foo->bar);
     // updating
     $this->assertSame(1, DBQuery::update('tests')->set('foo', 1, 'bar', 2)->where('id', $inserted_id)->act());
     // deleting
     $this->assertSame(1, DBQuery::delete('tests')->where('id', $inserted_id)->act());
     $this->assertFalse(DBQuery::select('tests')->where('id', $inserted_id)->act()->exists);
 }