コード例 #1
0
ファイル: cache.php プロジェクト: nbari/DALMP
$disk = new DALMP\Cache(new DALMP\Cache\Disk());
/**
 * database instance
 */
$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");
$sql = 'SELECT * FROM Country LIMIT 2';
/**
 * Cache for 5 minutes with key: mykey using memcache cache
 */
$db->useCache($memcache);
$rs = $db->CacheGetAll(300, $sql, 'mykey');
$timer->setMark('memcache');
echo count($rs), PHP_EOL;
$rs = $db->CacheGetAll(300, $sql, 'mykey');
$timer->setMark('memcache2');
echo count($rs), PHP_EOL;
/**
 * Cache for 5 minutes with key: mykey using redis cache
 */
$db->debug();
$db->useCache($redis);
$rs = $db->CacheGetAll(300, $sql, 'mykey');
$timer->setMark('redis');
echo count($rs), PHP_EOL;
$rs = $db->CacheGetAll(300, $sql, 'mykey');
$db->debug('off');
$timer->setMark('redis2');
コード例 #2
0
ファイル: cache-group-DSN.php プロジェクト: nbari/DALMP
# ------------------------------------------------------------------------------
$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');
echo count($rs), PHP_EOL;
$timer->setMark('default');
/**
 * lazy connection test query DB only when needed
 */
コード例 #3
0
ファイル: query_Execute.php プロジェクト: nbari/DALMP
<?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);