Esempio n. 1
0
 /**
  * getSessionsRefs
  *
  * @return array of sessions containing any reference
  */
 public function getSessionsRefs()
 {
     $refs = array();
     $db_refs = $this->DB->FetchMode('ASSOC')->GetAll("SELECT sid, ref, expiry FROM {$this->dalmp_sessions_table} WHERE ref IS NOT null");
     if ($db_refs) {
         foreach ($db_refs as $value) {
             $refs[$value['sid']] = array($value['ref'] => $value['expiry']);
         }
     }
     return $refs;
 }
Esempio n. 2
0
 /**
  * @depends testPCacheKey_1
  */
 public function testPCacheKey_2($data)
 {
     $rs = $this->db->FetchMode('ASSOC')->CachePGetALL('SELECT UNIX_TIMESTAMP() AS timestamp, FLOOR(0 + (RAND() * 1000)) AS rand, t1.name, t1.District, t2.Capital, t2.Localname, t2.Region, t2.SurfaceArea, t2.Population FROM City t1 LEFT JOIN Country t2 ON t1.countrycode=t2.code WHERE t2.population < ?', 10000, 'mykey');
     $this->assertEquals($data, $rs);
     $rs2 = $this->db->CacheFlush('SELECT UNIX_TIMESTAMP() AS timestamp, FLOOR(0 + (RAND() * 1000)) AS rand, t1.name, t1.District, t2.Capital, t2.Localname, t2.Region, t2.SurfaceArea, t2.Population FROM City t1 LEFT JOIN Country t2 ON t1.countrycode=t2.code WHERE t2.population < ?', 'mykey');
     $this->assertTrue((bool) $rs2);
     $rs = $this->db->FetchMode('ASSOC')->CachePGetALL(2, 'SELECT UNIX_TIMESTAMP() AS timestamp, FLOOR(0 + (RAND() * 1000)) AS rand, t1.name, t1.District, t2.Capital, t2.Localname, t2.Region, t2.SurfaceArea, t2.Population FROM City t1 LEFT JOIN Country t2 ON t1.countrycode=t2.code WHERE t2.population < ?', 10000, 'mykey');
     $this->assertNotEquals($data, $rs);
     sleep(1);
     $rs2 = $this->db->FetchMode('ASSOC')->CachePGetALL('SELECT UNIX_TIMESTAMP() AS timestamp, FLOOR(0 + (RAND() * 1000)) AS rand, t1.name, t1.District, t2.Capital, t2.Localname, t2.Region, t2.SurfaceArea, t2.Population FROM City t1 LEFT JOIN Country t2 ON t1.countrycode=t2.code WHERE t2.population < ?', 10000, 'mykey');
     $this->assertEquals($rs2, $rs);
     sleep(1);
     $rs = $this->db->FetchMode('ASSOC')->CachePGetALL(1, 'SELECT UNIX_TIMESTAMP() AS timestamp, FLOOR(0 + (RAND() * 1000)) AS rand, t1.name, t1.District, t2.Capital, t2.Localname, t2.Region, t2.SurfaceArea, t2.Population FROM City t1 LEFT JOIN Country t2 ON t1.countrycode=t2.code WHERE t2.population < ?', 10000, 'mykey');
     $this->assertNotEquals($rs2, $rs);
 }
Esempio n. 3
0
 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'));
 }
Esempio n. 4
0
<?php

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_HOST') ?: '3306';
/**
 * Cache engine defined on DSN
 */
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp?redis:127.0.0.1:6379");
$db->FetchMode('ASSOC');
/**
 * Cache for 5 minutes, group A
 */
$rs = $db->CachePGetAll(300, 'SELECT * FROM Country WHERE Region = ?', 'Caribbean', 'group:A');
echo count($rs), PHP_EOL;
$timer->setMark('300');
/**
 * Cache for 1 day (86400 seconds), group B
 */
$rs = $db->CachePGetAll(86400, 'SELECT * FROM Country WHERE Continent = ?', 'Europe', 'group:B');
echo count($rs), PHP_EOL;
$timer->setMark('86400');
/**
 * Cache for 1 hour (default), group C
 */
$rs = $db->CachePGetAll('SELECT * FROM Country WHERE Population <= ?', 100000, 'group:C');
Esempio n. 5
0
<?php

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");
$rs = $db->FetchMode('ASSOC')->PGetAll('SELECT @i:=@i+1 AS iterator, t.* from Country as t, (SELECT @i:=0) AS r');
print_r($rs);
# ------------------------------------------------------------------------------
echo PHP_EOL, str_repeat('-', 80), PHP_EOL;
echo str_repeat('-', 80), PHP_EOL, 'Time: ', $timer->getPageLoadTime(), ' - Memory: ', $timer->getMemoryUsage(1), PHP_EOL, str_repeat('-', 80), PHP_EOL;
Esempio n. 6
0
<?php

require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
$db1 = new DALMP\Database('utf8://dalmp:password@127.0.0.1:3306/dalmptest');
$db2 = new DALMP\Database('uft8://root:' . rawurlencode('pass-?/:word') . '@remote.localbox.org:3307/dalmptest');
$rs1 = $db1->FetchMode('ASSOC')->getall('SELECT * FROM Country limit 1');
print_r($rs1);
$rs2 = $db2->FetchMode('NUM')->getall('SELECT * FROM City limit 1');
print_r($rs2);
# ------------------------------------------------------------------------------
echo PHP_EOL, str_repeat('-', 80), PHP_EOL, 'Time: ', $timer->getPageLoadTime(), ' - Memory: ', $timer->getMemoryUsage(1), PHP_EOL, str_repeat('-', 80), PHP_EOL;
Esempio n. 7
0
<?php

error_reporting(-1);
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';
$dsns = array('utf8://root:mysql@127.0.0.1/dalmp3', 'utf8://root:mysql@127.0.0.1/dalmp4', 'utf8://root:mysql@127.0.0.1/dalmp5', "utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
$cdb = new DALMP\Database($dsns[0]);
$result = false;
while (!$result) {
    try {
        $result = $cdb->FetchMode('ASSOC')->PgetAll('SELECT NOW()');
    } catch (\Exception $e) {
        array_shift($dsns);
        $cdb = new DALMP\Database($dsns[0]);
        if ($dsns) {
            $cdb = new DALMP\Database($dsns[0]);
        } else {
            throw $e;
        }
        echo $e->getMessage(), PHP_EOL;
    }
}
print_r($result);
#------------------------------------------------------------------------------
echo PHP_EOL, str_repeat('-', 80), PHP_EOL, 'Time: ', $timer->getPageLoadTime(), ' - Memory: ', $timer->getMemoryUsage(1), PHP_EOL, str_repeat('-', 80), PHP_EOL;
Esempio n. 8
0
 * An array containing the SSL parameters must be passed as the second argument to the database method:
 *
 * $db = new DALMP(DSN, $ssl_array);
 *
 * key    = The path name to the key file.
 * cert   = The path name to the certificate file.
 * ca     = The path name to the certificate authority file.
 * capath = The pathname to a directory that contains trusted SSL CA certificates in PEM format.
 * cipher = A list of allowable ciphers to use for SSL encryption.
 *
 */
$ssl = array('key' => null, 'cert' => null, 'ca' => 'mysql-ssl.ca-cert.pem', 'capath' => null, 'cipher' => null);
$db = new DALMP\Database('latin1://root:mysql@127.0.0.1/dalmp', $ssl);
try {
    $db->getOne('SELECT NOW()');
    print_r($db->FetchMode('ASSOC')->GetRow("show variables like 'have_ssl'"));
} catch (\Exception $e) {
    print_r($e->getMessage());
}
/**
* If you have SSL will get something like:
Array
(
 [Variable_name] => have_ssl
 [Value] => YES
)
* otherwise
*
Array
(
 [Variable_name] => have_ssl
Esempio n. 9
0
<?php

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();
$values = array(array(1, 2, 3), array(1, 3), array('date', 'select', 3), array('niño', 'coraçao', 'Ú'), array(null, 5, 7));
$rs = $db->multipleInsert('tests', array('col1', 'col2', 'col3'), $values);
var_dump($rs);
print_r($db->FetchMode('ASSOC')->GetALL('SELECT * FROM tests'));
# ------------------------------------------------------------------------------
echo PHP_EOL, str_repeat('-', 80), PHP_EOL, 'Time: ', $timer->getPageLoadTime(), ' - Memory: ', $timer->getMemoryUsage(1), PHP_EOL, str_repeat('-', 80), PHP_EOL;
Esempio n. 10
0
<?php

require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
$timer->setMark('start');
$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->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);