Login   Register  
PHP Classes
elePHPant
Icontem

File: cached_mysql_query.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of V. Yanson  >  RS Cache  >  cached_mysql_query.php  >  Download  
File: cached_mysql_query.php
Role: Example script
Content type: text/plain
Description: Small script to show how you can implement the rscache class to cache mysql queries. Should only be implemented with SELECT queries.
Class: RS Cache
Store and retrieve variables from cache files
Author: By
Last change:
Date: 2005-09-09 09:27
Size: 581 bytes
 

Contents

Class file image Download
<?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)
{
    ...
}

?>