1
Basicaly是我第一次使用memcached ...我試圖運行一個簡單的查詢,由於某種原因沒有工作...有關memcached的教程不是很好,我有不知道爲什麼不工作我查詢MySQL&Memcached - 簡單的檢索查詢不起作用
<?php
//connect to memcached server and MySQL
$db = new PDO('mysql:host=localhost;dbname=test', 'admin', '');
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
// Run the query and get the data from the database then cache it
$category_querry = $db->query('SELECT * FROM category WHERE category_id=1');
$category_querry->setFetchMode(PDO::FETCH_ASSOC);
while($row = $category_querry->fetch()) {
$memcache->set(1, $row['category_name'], 30); // Store the result of the query for 20 seconds
var_dump($memcache->get(1));
echo "</br> Data Pulled from the Database </br>";
}
$get_result = $memcache->get(1);
var_dump($get_result);
if ($get_result)
{
echo "</br>" . $get_result['category_name'];
echo "</br>" . "Data Pulled From Cache";
}
代碼更新現在不知何故,我使其進入IF語句,什麼顯示在瀏覽器中
string(3) "one"
Data Pulled from the Database
string(3) "one"
o
Data Pulled From Cache
這就讓我發現,所有的var_dumps工作....並且到達t他如果陳述但不知何故$get_result['category_name']
只輸出o
當它應該輸出one
爲什麼???
設置它來定義$關鍵$鍵=「SELECT * FROM類別WHERE CATEGORY_ID = 1「;在while循環之前。仍然沒有進入下面的IF語句......有趣的是,當我在while語句中執行'var_dump($ row)'時,它返回並且錯誤 – 2012-07-27 08:48:27
它返回什麼錯誤? – 2012-07-27 08:53:39
未定義的變量:第16行的C:\ Program Files(x86)\ Zend \ Apache2 \ htdocs \ interview \ 1.php中的var_dump – 2012-07-27 08:59:38