예제 #1
0
파일: test_dalmp.php 프로젝트: nbari/DALMP
 public function testTransactions()
 {
     $this->assertEquals(0, $this->db->Execute('CREATE TABLE IF NOT EXISTS t_test (id INT NOT NULL PRIMARY KEY) ENGINE=InnoDB'));
     $this->assertEquals(0, $this->db->Execute('TRUNCATE TABLE t_test'));
     $this->assertEquals(0, $this->db->StartTrans());
     $this->assertTrue($this->db->Execute('INSERT INTO t_test VALUES(1)'));
     $this->assertEquals(0, $this->db->StartTrans());
     $this->assertTrue($this->db->Execute('INSERT INTO t_test VALUES(2)'));
     $this->assertEquals(array(array('id' => 1), array('id' => 2)), $this->db->FetchMode('ASSOC')->GetAll('SELECT * FROM t_test'));
     $this->assertEquals(0, $this->db->StartTrans());
     $this->assertTrue($this->db->Execute('INSERT INTO t_test VALUES(3)'));
     $this->assertEquals(array(array('id' => 1), array('id' => 2), array('id' => 3)), $this->db->FetchMode('ASSOC')->GetAll('SELECT * FROM t_test'));
     $this->assertEquals(0, $this->db->StartTrans());
     $this->assertTrue($this->db->Execute('INSERT INTO t_test VALUES(7)'));
     $this->assertEquals(array(array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 7)), $this->db->FetchMode('ASSOC')->GetAll('SELECT * FROM t_test'));
     $this->assertEquals(0, $this->db->RollBackTrans());
     $this->assertTrue($this->db->CompleteTrans());
     $this->assertTrue($this->db->CompleteTrans());
     $this->assertTrue($this->db->CompleteTrans());
     $this->assertEquals(array(array('id' => 1), array('id' => 2), array('id' => 3)), $this->db->FetchMode('ASSOC')->GetAll('SELECT * FROM t_test'));
 }
예제 #2
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;