Esempio n. 1
0
$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');
echo count($rs), PHP_EOL;
/**
 * Cache for 5 minutes with key: mykey using disk cache
 */
$db->useCache($disk);
$rs = $db->CacheGetAll(300, $sql, 'mykey');
$timer->setMark('disk');
echo count($rs), PHP_EOL;
Esempio n. 2
0
/**
 * 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
 */
$db->debug();
$db->closeConnection();
/**
 * Cache for 5 minutes, group A
 */
$rs = $db->CachePGetAll('SELECT * FROM Country WHERE Region = ?', 'Caribbean');
echo count($rs), PHP_EOL;
$timer->setMark('lazy');
/**
 * flush only group A
 */
$db->CacheFlush('group:A');
/**
 * Cache for 5 minutes, group A
 */
$rs = $db->CachePGetAll(300, 'SELECT * FROM Country WHERE Region = ?', 'Caribbean', 'group:A');
Esempio n. 3
0
(
 [Variable_name] => Ssl_cipher
 [Value] => DHE-RSA-AES256-SHA
)
* otherwise
Array
(
 [Variable_name] => Ssl_cipher
 [Value] =>
)
*/
/**
 * example using a socket for the connection
 *
 * charset: utf8
 * user: $user
 * password: $password
 * socket path: /tmp/mysql.sock
 * database: dalmp
 */
$db = new DALMP\Database("utf8://{$user}:{$password}" . '@unix_socket=\\tmp\\mysql.sock/dalmp');
$db->debug(1);
try {
    echo PHP_EOL, 'example using unix_socket: ', $db->getOne('SELECT NOW()'), PHP_EOL;
} catch (\Exception $e) {
    print_r($e->getMessage());
}
echo $db;
// will print: DALMP :: connected to: db4, Character set: utf8, Localhost via UNIX socket,...
# -----------------------------------------------------------------------------------------------------------------
echo PHP_EOL, str_repeat('-', 80), PHP_EOL, 'Time: ', $timer->getPageLoadTime(), ' - Memory: ', $timer->getMemoryUsage(1), PHP_EOL, str_repeat('-', 80), PHP_EOL;