Exemplo n.º 1
0
 public function testGetall()
 {
     $rs = $this->db->GetAll('SELECT * FROM Country WHERE Continent = "North America"');
     $this->assertEquals(37, count($rs));
     $this->assertEquals('Mexico', $rs['23'][1]);
     $this->assertEquals('414972.00', $rs['23']['GNP']);
 }
Exemplo n.º 2
0
 /**
  * @depends testCacheGetAll_0
  */
 public function testCacheGetAll_1($data)
 {
     $rs = $this->db->CacheGetAll(1, "SELECT *, UNIX_TIMESTAMP() AS timestamp,  FLOOR(0 + (RAND() * 1000)) AS rand FROM Country WHERE Continent = 'North America'");
     $rs2 = $this->db->GetAll("SELECT *, UNIX_TIMESTAMP() AS timestamp,  FLOOR(0 + (RAND() * 1000)) AS rand FROM Country WHERE Continent = 'North America'");
     $this->assertEquals($data, $rs);
     $this->assertNotEquals($rs2, $rs);
     return $data;
 }
Exemplo n.º 3
0
require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_PORT') ?: '3306';
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
$db->debug();
$db->Execute('CREATE TABLE IF NOT EXISTS t_test (id INT NOT NULL PRIMARY KEY) ENGINE=InnoDB');
$db->Execute('TRUNCATE TABLE t_test');
$db->FetchMode('ASSOC');
$db->StartTrans();
$db->Execute('INSERT INTO t_test VALUES(1)');
$db->StartTrans();
$db->Execute('INSERT INTO t_test VALUES(2)');
print_r($db->GetAll('SELECT * FROM t_test'));
$db->StartTrans();
$db->Execute('INSERT INTO t_test VALUES(3)');
print_r($db->GetAll('SELECT * FROM t_test'));
$db->StartTrans();
$db->Execute('INSERT INTO t_test VALUES(7)');
print_r($db->GetALL('SELECT * FROM t_test'));
$db->RollBackTrans();
print_r($db->GetALL('SELECT * FROM t_test'));
$db->CompleteTrans();
$db->CompleteTrans();
$db->CompleteTrans();
# ------------------------------------------------------------------------------
echo PHP_EOL, str_repeat('-', 80), PHP_EOL, 'Time: ', $timer->getPageLoadTime(), ' - Memory: ', $timer->getMemoryUsage(1), PHP_EOL, str_repeat('-', 80), PHP_EOL;
Exemplo n.º 4
0
$db->FetchMode('NUM');
$sql = 'SELECT * FROM City';
$rs = $db->Execute($sql);
if ($rs) {
    while (($rows = $db->query()) != false) {
        list($r1, $r2, $r3) = $rows;
        echo "w1: {$r1}, w2: {$r2}, w3: {$r3}", $timer->isCli(1);
    }
}
$timer->setMark('while');
/**
 * doing the same but consuming more memory.
 * Below the returned $rs2 array is not referential. Because of that, the system
 * will use excesive memory. With large columns.
 */
$rs2 = $db->GetAll($sql);
foreach ($rs2 as $value) {
    list($r1, $r2, $r3) = $value;
    echo "f1: {$r1}, f2: {$r2}, f3: {$r3}", $timer->isCli(1);
}
$timer->setMark('foreach');
/**
 * prepared statements
 * and array needs to be passed as an argument
 */
$rs = $db->PExecute('SELECT * FROM Country WHERE Continent = ?', 'Europe');
$out = array();
while ($rows = $db->Pquery($out)) {
    print_r($out);
}
$rs = $db->PExecute('UPDATE Country SET code=? WHERE Code="PRT"', 'PRT');