Just playing around with memcache for the first time; here’s my code:
$memcache = new Memcache();
$memcache->connect('127.0.0.1', 11211) or die('Memcache connection error');
// set the key then check the cache
$key = md5(' SELECT * FROM `users` ');
$get_result = $memcache->get($key);
if($get_result) {
echo "Data Pulled From Cache";
var_dump($get_result);
}
else {
$query = ' SELECT * FROM `users` ';
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$memcache->set($key, $row, TRUE, 20); // stored for 20 seconds
echo "Data Pulled from the Database";
var_dump($row);
}
I have 50,000 dummy users in my users table, how come the var dump only shows the 1st user? As you can see there are no limit clauses in the query.
You’re only fetching one row from the
$resultresource. If you want a full rowset, you need to fetch each row in awhileloop and append them onto an array: