I found the below example of using memcache for mysql
$sSQL = "SELECT some really heavy stuff FROM some table";
function cachedSQL($sSQL) {
if($objResultset = clsMem::getMem()->get(MD5($sSQL)) {
// return the cached resultset
return $objResultSet;
}
else {
// assuming we have a PEAR::DB based database
// singleton handling the query
$objResultSet = DB::getDB()->query->($sSQL);
// Store the resultset in the cache
clsMem::getMem()->set(MD5($sSQL), $objResultSet, true, 600);
// return it
return $objResultSet;
}
}
Im a bit confused with this "PEAR:😃B based database " I dont use this style could someone show me how to modify this to work withough that style, assuming I am already connected to my DB at all times?
UPDATE
I found this example now but I dont understand hwat to use near this line
$result = $query_results_mangled_into_most_likely_an_array`
$key = md5('SELECT * FROM rest_of_sql_statement_goes_here');
if ($memcache->get($key)) {
` return $memcache->get($key);`
}
else {
` // Run the query and transform the result data into your final dataset form`
` $result = $query_results_mangled_into_most_likely_an_array`
` $memcache->set($key, $result, TRUE, 86400); // Store the result of the query for a day`
` return $result;`
}
And here is real code from my site that I would like to use memcache to cache and update after x amount of time
<?php
//Get 2 newest members
$sql_latest='SELECT auto_id,disp_name FROM friend_reg_user ORDER BY auto_id DESC LIMIT 0 , 2';
$result_latest=executequery($sql_latest);
while($line_latest = mysql_fetch_assoc($result_latest)){
echo '<td align="center">';
show_user_photo_name($line_latest['auto_id'],$photo_type='small',$line_latest['disp_name'], $online = 'yes');
//show_user_photo($line_latest['auto_id'], 'small', 'yes');
echo '</td>';
}
?>