Is there a way to cache results of a mysql query manually to a txt file?
Ex:
$a=1;
$b=9;
$c=0;
$cache_filename = 'cached_results/'.md5("$a,$b,$c").'.txt';
if(!file_exists($cache_filename)){
$result = mysql_query("SELECT * FROM abc,def WHERE a=$a AND b=$b AND c=$c");
while($row = mysql_fetch_array($result)){
echo $row['name'];
}
// Write results on $row to the txt file for re-use
}else{
// Load results just like $row = mysql_fetch_array($result); from the txt file
}
The original query contains more WHEREs and joins that uses multiple tables. So, Is this possible? If so, please explain.
Thank you, pnm123
If you're sure that your data has a long time-to-live, you can certainly cache data by saving it temporarily to a text file.
Although using APC, MemCache, or XCache would be a better alternative if you consider performance.