<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
You cannot directly store a MySQL result set. I believe this is
because it's actually a reference and when it's converted to a string
you will simply be storing "MySQL Result Set" instead of the result of
your query.<br>
<br>
My solution to this problem has been to turn my MySQL results into a
PHP array where each row in the resultset is an item in the array.
These items are arrays themselves with their keys being the column
name. So if your result set returned names and phone numbers the array
would be something like this:<br>
<br>
$MyResultSetArray = array();<br>
$MyResultSetArray[] = array('first_name' => 'Bob', 'last_name' =>
'Johnson', 'phone' = '555-555-5555');<br>
<br>
You then store the array in memcache. If you write a class you can do
all this transparently. Something like: <br>
<br>
MyClass->query(theSQL, addToCache)<br>
<br>
and have it return the array mentioned above, regardless of whether it
was pulled from the cache or generated on the fly.<br>
<br>
This gives you the greatest flexibility with what you can do with your
resultset. However, you will have to devise a method to ensure your
data is not stale. My website, Gigoit, uses very consistent SQL
queries that can easily be cached. When new items are posted to our
site we run code to remove any keys that could be stale. If you
describe your situation in more detail, I might be able to give you
more information.<br>
<br>
- John<br>
<br>
<a class="moz-txt-link-freetext" href="http://www.Gigoit.org">http://www.Gigoit.org</a>
- Give and Get Free Items in your Area. (Saving the planet is just a
bonus)
<br>
<br>
<br>
Ajinkya Nahar wrote:
<blockquote cite="mid:20070904060229.82E80906E0@mail.danga.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; ">
<meta name="Generator" content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
<div class="Section1">
<p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;">Hi,<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;">I am working on a PHP –
Mysql application.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;">I wanted to ask that can
we cache the result set returned by
a particular query into memcached?<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;">If yes, can we fetch the
same result set from memcached and
use it without database connection?<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;">E.g.<o:p></o:p></span></font></p>
<p class="MsoNormal" style="text-indent: 0.5in;"><font color="#7f9fbf"
face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: rgb(127, 159, 191);">$query</span></font><font
color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;"> = “</span></font><font
color="#2a00ff" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: rgb(42, 0, 255);">SELECT
* from ……”;</span></font><font face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New";"><o:p></o:p></span></font></p>
<p class="MsoNormal"><font color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;">
</span></font><font color="#7f9fbf" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: rgb(127, 159, 191);">$result</span></font><font
color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;"> = </span></font><font
color="#7f7f9f" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: rgb(127, 127, 159);">mysql_query</span></font><font
color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;">(</span></font><font
color="#7f9fbf" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: rgb(127, 159, 191);">$query</span></font><font
color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;">);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;">
$memcache_obj->set($key,
$result);<o:p></o:p></span></font></p>
<p class="MsoNormal"><font color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;">Will
this work??<o:p></o:p></span></font></p>
<p class="MsoNormal"><font color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;">Please
let me
know your comments.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;">Regards,<o:p></o:p></span></font></p>
<p class="MsoNormal"><font color="black" face="Courier New" size="2"><span
style="font-size: 11pt; font-family: "Courier New"; color: black;">Ajinkya</span></font><font
face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;"><o:p></o:p></span></font></p>
</div>
</blockquote>
<br>
</body>
</html>