connect($memcachehost,$memcacheport) or die ("Could not connect"); $query="select * from personal_info limit 10"; $key=md5($query); if(!$memcache->get($key)) { $conn=mysql_connect("localhost","root","passwd"); mysql_select_db(mydb); $result=mysql_query($query); while ($row=mysql_fetch_assoc($result)) { $arr[]=$row; } $f = 'mysql'; $memcache->add($key,serialize($arr),0,30); //mysql 查询后,插入 memcached $data = $arr ; } else{ $f = 'memcache'; $data_mem=$memcache->get($key); $data = unserialize($data_mem); } echo $f; echo ""; //print_r($data); foreach($data as $a) { echo "number is $a[pi_id]"; echo ""; echo "name is $a[pi_name]"; echo ""; echo "tel is $a[pi_tel]"; echo ""; echo "qq is $a[pi_qq]"; echo ""; echo "email is $a[pi_email]"; echo ""; } ?>