<?php
include_once("cache.php");
function cached_mysql_query($db, $query)
{
$cache = new cache();
$return = array();
$uid = md5($query);
$ret = $cahce->get($uid);
if (!$ret)
{
$q = mysql_query($query, $db);
while ($p = mysql_fetch_array($q))
{
foreach ($p as $n => $v)
{
if (!is_numeric($n)) $return[$n] = $v;
}
}
$cache->save($uid, $return);
}
return $return;
}
$db = mysql_connect(...);
mysql_select_db(...);
foreach (cached_mysql_query(& $db, "select * from ... where ...") as $n => $v)
{
...
}
?>
|