connect('localhost',6379); if($redis->exists("blog")){ $b=$redis->get("blog"); $rs=unserialize($b)">
 | 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

Redis应用于php,连接mysql的完整案例

<?php                  header("Content-type:text/html;charset=utf-8");                  error_reporting(0);                  $redis=new Redis();                  $redis->connect('localhost',6379);                  if($redis->exists("blog")){                  $b=$redis->get("blog");                  $rs=unserialize($b);                       foreach($rs as $res){                          echo $res['title']."<br/>";                  }                   }                   else{                    $conn=  mysql_connect("localhost","root","root");                  mysql_select_db("test");                  mysql_query("set names utf8");                  $sql="select * from blog";                  $result=mysql_query($sql);                  $rss=array();                  while($rs=mysql_fetch_assoc($result)){                  $rss[]=$rs;                  $redis->set("blog", serialize($rss));                  $b=$redis->get("blog");                  $rs=unserialize($b);                        foreach($rs as $res){                            echo $res['title']."<br/>";                  }                  }                   }