// $__oradb->setOption('portability', DB_PORTABILITY_LOWERCASE); require_once "config.php"; require_once "sqlrelay.php"; unset($__config['sqlrelay_dsn']); $__config['sqlrelay_dsn'][]="sqlrelay://xx_id:[email protected]:9000"; $sql="select aaa,bbb from xxxx t where g_close_date is null"; $__now=get_microtime(); $__oradb=_fn_connect_sqlrelay(); $__oradb->setOption('portability', DB_PORTABILITY_LOWERCASE); $result = $__oradb->query($sql); if (DB::isError($result)) { echo "db error\n"; printf("Execution time : %s\n",get_microtime()-$__now); exit; } while ( $row=$result->fetchRow(DB_FETCHMODE_ASSOC) ) { // ----- echo $row['aaa'] . ' : ' . $row['bbb']; } $result->free(); $__oradb->disconnect(); // 取時間 function function get_microtime() { list($usec, $sec) = explode(' ',microtime() ); return ((double)$usec + (double)$sec); }
Programming/php
查表法 , PHP 把 array 存進 file
好處是, 下次直接把檔讀進 array 立即可查詢, 如果資料不常改變, 查詢頻率普通時用
my encode sample
[code language=php]
// my_encode( )
$secret = ‘11111’;
function my_encode($data) {
$data = serialize($data);
$hash = md5($GLOBALS[‘secret’] . $data);
return array($data, $hash);
}
// my_decode( )
function my_decode($data, $hash) {
if (!empty($data) && !empty($hash)) {
if (md5($GLOBALS[‘secret’] . $data) == $hash) {
return unserialize($data);
} else {
error_log(“Validation Error: Data has been modified”);
return false;
}
}
return false;
}
TEST: $secret = ‘11111’;
// Load in and validate old dataif (! $data = my_decode($_GET[‘data’], $_GET[‘hash’])) {// crack attempt}// Process form (new form data is in $_GET)// Update $data$data[‘username’] = $_GET[‘username’];$data[‘stage’]++;unset($data[‘password’]);// Encode resultslist ($data, $hash) = pc_encode($data);// Store data and hash inside the form?> ” method=”get”>
…
value=””>
value=””>
[/code]
PHP: cachelite program sample
emerge dev-php/PEAR-Cache_Lite
require_once "Cache/Lite.php"; define('ENABLE_CACHE_LITE',1); function _fn_get_data_from_cache($key) { $options = array( 'cacheDir' => '/tmp/', 'lifeTime' => 10, 'pearErrorMode' => CACHE_LITE_ERROR_DIE ); if (ENABLE_CACHE_LITE) { $cache=new Cache_Lite($options); if ($data=$cache->get($key)) { // got data from cache_lite then return return $data; } } // not found! then do the process // sample $data=time(); if (ENABLE_CACHE_LITE) { $cache->save($data); } return $data; } // ====== $key='abc'; echo _fn_get_data_from_cache($key);