将数据库中的数据取到memcache中

来源:互联网 发布:淘宝上很灵的风水店 编辑:程序博客网 时间:2024/05/02 03:01

我这里使用的是php链接到数据库中,从数据中取出数据放到缓存中


require_once 'memcache.php';

$memcache = new Memcache();
$memcache->connect('127.0.0.1', 11211);   //链接本机的memcache

$db_connect = mysql_connect('192.168.1.254','root','123456') or die('error:'.mysql_error());  //链接数据库
$db = mysql_select_db('hfoa') or die('error'.mysql_error()); 
$charset = mysql_set_charset('utf8',$db_connect) ;
$res = mysql_query('select * from sym_modules ;',$db_connect) or die('mysql_error'.mysql_error($db_connect)) ;  //取数据

while($row = mysql_fetch_array($res)){                                             //将结果缓存到数据库中
    $memcache->add($row[0],$row[4] , 0, 50);
}

0 0
原创粉丝点击