/** * Execute the query * * @param string $q query sql * @param array $p array of binding values * @return object result of the query */ public function query(string $q, array $p = NULL) { if ($p == null) { $p = $this->builder->getPrepare(); } return empty($p) ? DB::query($q) : DB::execute($q, $p); }
/** * Execute a query */ public function query($q) { return DB::query($q); }
/** * Execute the query and return a result as array * * @param PDOStatement|SQL code $q PDO object * @return array result */ public static function fetch($q, $nIndex = true) { if (is_string($q)) { $q = DB::query($q); } return $nIndex ? $q->fetchAll() : $q->fetchAll(PDO::FETCH_ASSOC); }
public function testRestore() { # -------------------------------------------------------------------------- DB::query("TRUNCATE users"); # -------------------------------------------------------------------------- # Insert some data DB::query("INSERT INTO users (username,password) VALUES ('admin','admin')"); # -------------------------------------------------------------------------- # Save the table DB::save('users'); # Perform some query DB::query("TRUNCATE users"); # Now users is recovered! DB::undo(); # Check $this->assertEquals(DB::count(DB::query("SELECT * FROM users")), 1); # -------------------------------------------------------------------------- # Save the table DB::save('users'); # Perform some query DB::query("TRUNCATE users"); # Now users is empty! DB::confirm(); # Check $this->assertEquals(DB::count(DB::query("SELECT * FROM users")), 0); # After several rows of code... # Restore the LAST SAVE POINT DB::restore(); # Check $this->assertEquals(DB::count(DB::query("SELECT * FROM users")), 1); # -------------------------------------------------------------------------- # But WAIT! You can undo the previous restore! DB::restore(); # Check $this->assertEquals(DB::count(DB::query("SELECT * FROM users")), 0); # -------------------------------------------------------------------------- # Oh yeah, restore the restore of restore point! (undo x3) DB::restore(); # Check $this->assertEquals(DB::count(DB::query("SELECT * FROM users")), 1); # -------------------------------------------------------------------------- DB::query("TRUNCATE users"); # -------------------------------------------------------------------------- }