Problem with mysql result

Caveo Internet B.V. - Martin martin at caveo.nl
Sun Jul 30 11:58:28 UTC 2006


Hi Guys,

Just starting with memcached and php4 , and i just cant get this to work , all i want is to store the mysql result into memcache for future use , but somehow it doesn't work and i can't find any solution googling around...

Maybe someone from this list could help me out ?

It always rreturns as 'not cached' thus hitting the DB .

The code :

<?php
include_once('../inc/db.inc');

$memcache = new Memcache;
$memcache->connect('IP', 1211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$test = $memcache->get('testqry');

if (!$test) {
 
 $time = microtime();
 $time = explode(" ", $time);
 $time = $time[1] + $time[0];
 $start = $time;
 
 echo "testqry is not cached.<br><Br>";
 
 $qry = "SELECT * from large_db ORDER by ID";
 $res = mysql_query($qry) or die(mysql_error());
 
 while ($row = mysql_fetch_array($res)) {
  
  echo $row['id']." - ".$row['title']." - ".$row['url']."<br>";
  
 }
 
 
 $memcache->set('testqry', $res, true, 600)or die("set failed");
 
 echo "Result stored in cache";

} else { 


 
 echo "testqry was cached.<br><Br>";
 
 $res = $memcache->get('testqry');
 
 echo $res;
 
}

?>

Thanks in advance,

    Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20060730/1286005d/attachment.html


More information about the memcached mailing list