Redis应用于php,连接mysql的完整案例
发布时间:2020-12-30 18:24:49 所属栏目:MySql教程 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 ?php header("Content-type:text/html;charset=utf-8"); error_reporting(0); $redis=new Redis(); $redis-connect('localhost',6379); if($redis-exi
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 <?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/>"; } } } 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:东莞站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- php – 编程初学者 – 设计Web应用程序的建议
- mysql – 根据子查询的结果更新表中的多行
- mysql 启动错误 InnoDB Operating system error number 13
- 如何在mySQL中分类为动态生成的特定顺序?
- MySql EntityFrameworkCore System.TypeLoadException
- 一份完整的阿里云Redis开发规范,值得收藏!
- MySQL适用于哪些情况?
- 将PHP PDO查询编写为`dbName` .tableName`而不是`tableName
- 官方工具|MySQL Router高可用原理与实战
- SQL Server注意事项总结,高级程序员必背!