php memcache访问数据库

来源:互联网 发布:More 查看sql文件乱码 编辑:程序博客网 时间:2024/05/22 16:59
<?php


$mem = new memcache();


$con = mysql_connect("localhost","root","");

if(!$con)
{
    
    die('Could not connect:'.mysql_errno());
}
mysql_select_db("mydatabase",$con);

$sql="INSERT INTO student (name,age) values ('wang','33')";
mysql_query($sql);
$sql1 = "INSERT INTO student (name,age) values ('zhang','55')";
mysql_query($sql1);

$sql2= "select * from student";
$mem->connect ('localhost','11211' ) or die ( "Could not connect" );

function memcache_sql($sql)
{
    
    global $mem;
    $key = md5('2');
    if(!$mem->get($key))
    {
        
        echo "in sql";
        $mem->add($key, "meimei");
    }
    else
    {
        echo "incache";
    }
}

memcache_sql($sql2);

mysql_close($con);
?>