码迷,mamicode.com
首页 > Web开发 > 详细

php memcache缓存

时间:2018-07-20 22:29:22      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:没有   sqli   pre   style   cti   sql   dump   nbsp   result   

<?php
    phpinfo();
    header("Content-type: text/html; charset=utf-8");
    $db = new mysqli("localhost","root","","ceshi");
    $mem = new Memcache;
    $mflag = $mem->connect("localhost", 11211);
    //var_dump($db);
    $sql = "select * from student";
    $a = query_memcache($sql);
    //var_dump($a);
    function query_memcache($sql,$type=‘‘){
          global $mem;
          global $db;
          $key = md5($sql);
          if(!($value = $mem->get($key))){ //Cache中没有,则从MySQL中查询
           $result = $db->query($sql);
           while($reattr = $result->fetch_assoc()){
                 $attr[] = $reattr;
           }
           $value = $attr;
           
           //将Key和Value写入MemCache
           $mem->set($key,$value,0,time()+30);//set(key,value,过期时间/单位秒);
          }
          return $value;
     }
?>

 

php memcache缓存

标签:没有   sqli   pre   style   cti   sql   dump   nbsp   result   

原文地址:https://www.cnblogs.com/sunhao1987/p/9343730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!