2015-05-14 80 views
-1

有人可以請幫助我如何通過PHP連接到mySQL使用memcached服務器?如何使用memcached與PHP和MYSQL

我有以下腳本,需要使用memcached的:

$dbserver="server"; 
$dbuser="user"; 
$dbpass="pass"; 
$dbname="db"; 
function dbcon(){ 
    @$spojenie=mysql_connect($GLOBALS["dbserver"],$GLOBALS["dbuser"],$GLOBALS["dbpass"]); 
    mysql_query("SET NAMES utf8"); 
    if (!$spojenie){ 
    die('error'); 
    } 
    mysql_select_db($GLOBALS["dbname"],$spojenie); 
    return $spojenie; 
} 
$dbspojenie=dbcon(); 
$GLOBALS["dbspojenie"]=&$dbspojenie; 

謝謝非常mutch的幫助。

回答

0

閱讀說明書memcache

<?php 
    $mysqli = new mysqli("host", "user", "passwd", "database"); 
    $memc = new Memcached(); 
    $memc->addServer("host", 11211); 
    mysqlnd_memcache_set($mysqli, $memc, NULL, 'var_dump'); 

    /* This query will be intercepted and executed via Memcache protocol */ 
    echo "Sending query for id via Memcache: "; 
    $mysqli->query("SELECT f1, f2, f3 FROM test WHERE id = 1"); 

    /* f1 is not configured as valid key field, this won't be sent via Memcache */ 
    echo "Sending query for f1 via Memcache: "; 
    $mysqli->query("SELECT id FROM test WHERE f1 = 1"); 

    mysqlnd_memcache_set($mysqli); 

    /* Now the regular MySQL protocol will be used */ 
    echo "var_dump won't be invoked: "; 
    $mysqli->query("SELECT f1, f2, f3 WHERE id = 1"); 

    ?> 
+0

謝謝你,我不得不用新的內存緩存,而不是memcached的,因爲memcached的類不存在(我應該從什麼地方安裝呢?)和我有錯誤:致命錯誤:調用未定義函數mysqlnd_memcache_set() –