I found one stupid mistake in the code above. In the if statement, I should have used is_null().
But still, after fixing that I can not display the result. Paras On Apr 16, 7:11 pm, Paras <[email protected]> wrote: > I tried a sample php code which caches a query and then retrieves from > the cache. I am using a mysql table as follows: > > ID, name, city, phone > > I have a memcached server (128mb) running on the same computer as the > mysql server. (127.0.0.1). > > Here is the php code:- > > $memcache = new Memcache; > $memcache->connect('127.0.0.1', 11211) or die ("Could not connect to > memcached"); > > mysql_connect(localhost,$username,$password) or die ("unable to > connect to database!!!"); > > @mysql_select_db($database) or die( "Unable to select database"); > > $query='select * from memcached_trial;'; > > $key = md5($query); > $result = $memcache->get($key); > > echo $key; > echo $result; > > if($result == null) > { > echo(" ---result not in cache--- "); > $result=mysql_query($query) or die(mysql_error()." : $query"); > > $memcache->set($key,$result,0,0); > > } > > $num=mysql_numrows($result); > > mysql_close(); > > the result when I see this in the browser is > > d4adc05e7a5dad0e4d5098655acfba440 ---result not in cache--- SELECT * > FROM memcached_trial; ID Name City Phone > 1 Erich Giles Princeton 1 > 2 Craig Miles Deadwood 2 > 3 Omar Alvarez Harrisburg 3 > 4 Lionel Prince Pomona 4 > 5 Cade Love Titusville 5 > 6 Chester Christian Gainesville 6 > 7 Xenos Yang Kalispell 7 > 8 Stone Christensen Calumet City 8 > 9 Logan Hebert Oneida 9 > 10 Kasimir Boyle Alexandria 10 > > Does anyone have any idea why this is happening ? > > Thanks > Paras.
