Пример #1
0
 public function testCached()
 {
     $username = '******';
     Database::query("replace into TinyORMTest (username, value) values ('" . $username . "','testvalue') ")->execute();
     $username2 = 'testusername2';
     Database::query("replace into TinyORMTest (username, value) values ('" . $username2 . "','testvalue') ")->execute();
     $query = Database::query("select * from TinyORMTest where username=?")->useResultCache(60, array($username));
     $this->assertEquals($username, $query[0]['username']);
     $query = Database::query("select * from TinyORMTest where username=?")->useResultCache(60, array($username2));
     $this->assertEquals($username2, $query[0]['username']);
 }
Пример #2
0
 public static function tearDownAfterClass()
 {
     Database::query("DROP TABLE IF EXISTS `TinyORMTest`")->execute();
 }
Пример #3
0
 public function testDatabaseConnectivity()
 {
     $db = Database::query("select 1")->execute()->fetchScalar();
     $this->assertEquals(1, $db);
 }
Пример #4
0
 public function delete($criteria = null)
 {
     if (!$this->data[$this->primary_key] && !is_array($criteria)) {
         throw new Exception(get_called_class() . " instance does not have a value for its primary key field " . $this->primary_key);
     }
     $query = "DELETE FROM " . $this->table . " WHERE 1 AND ";
     if (is_array($criteria)) {
         $params = array();
         foreach ($criteria as $field => $value) {
             $query .= " `" . $field . "`=?";
             $params[] = $value;
         }
     } else {
         $query .= " `" . $this->primary_key . "`=?";
         $params = array($this->data[$this->primary_key]);
         $query .= " limit 1";
     }
     try {
         Database::query($query)->execute($params);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }