<?php //header('content-type:text/html;charset=utf-8'); $name=$_POST['name']; $pdo = new PDO('mysql:host=127.0.0.1;dbname=lianxi','root','root'); $pdo->exec('set names utf8'); $mem = new Memcache; $mem->connect('127.0.0.1',11211); if($cou=$mem->get('num')){ if($cou<9){ ++$cou; $mem->set('num',$cou); $sql="select * from one where name like '%$name%'"; $arr=$pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC); // $mem->flush(); }else if($cou==9){ ++$cou; $mem->set('num',$cou); $sql="select * from one where name like '%$name%'"; $arr=$pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC); $mem->set('arr',$arr); echo "这次是存进缓存"; // $mem->flush(); }else if($cou>9){ $arr=$mem->get('arr'); ++$cou; $mem->set('num',$cou); echo "这是缓存,没有读取数据库"; // $mem->flush(); } //$mem->flush(); }else{ $sql="select * from one where name like '%$name%'"; $arr=$pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC); $num=1; $mem->set('num',$num); echo "这是数据库"; // $mem->flush(); } ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <table border="1"> <tr> <td>编号</td> <td>名字</td> <td>密码</td> <td>时间</td> <td>状态值</td> </tr> <?php foreach ($arr as $key => $val ){ ?> <tr> <td><?php echo $val['id']?></td> <td><?php echo $val['name']?></td> <td><?php echo $val['pwd']?></td> <td><?php echo $val['time']?></td> <td><?php echo $val['sta']?></td> </tr> <?php }?> </table> </body> </html>
接上篇简单的Memcache应用
最新推荐文章于 2018-06-25 19:31:06 发布