2014-03-01 29 views
1

這是我在index.php文件主查詢如何使用phpfastcache?

我試圖用phpfastcache

$shorting = $conn->prepare("SELECT text,time FROM small WHERE active='0' ORDER BY time DESC LIMIT 10"); 
$shorting->execute(); 
while($obj = $shorting->fetch(PDO::FETCH_OBJ)){ 

<div id="lastnews_title"> 
<div><?php echo $obj->text; ?></div> 
<div style="text-align:left"> 
<?php echo timeTonow($obj->time); ?> 
</div> 

這個緩存此查詢是phpfastcache網站爲例

// Require Library 
require_once("../phpfastcache/phpfastcache.php"); 

// simple Caching with: 
$cache = phpFastCache(); 

// Try to get $products from Caching First 
// product_page is "identity keyword"; 
$products = $cache->get("product_page"); 

if($products == null) { 
    $products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS"; 
    // Write products to Cache in 10 minutes with same keyword 
    $cache->set("product_page",$products , 600); 
} 

// use your products here or return it; 
echo $products; 

我在寫require_once("../phpfastcache/phpfastcache.php");我的index.php

我不知道如何插入我的查詢在這個緩存類?

遺憾的英語不好

回答

0

你沒有一套圍繞這一組PHP語句

$shorting = $conn->prepare("SELECT text,time FROM small WHERE active='0' ORDER BY time DESC LIMIT 10"); 
$shorting->execute(); 
while($obj = $shorting->fetch(PDO::FETCH_OBJ)){ 

這段代碼看起來並不像它的功能<php>標籤,我認爲這是你在這裏得到的觀點。

你應該學習一些PHP的基礎知識。我對PHP和你想做的事情知之甚少,但我知道這是糟糕的「php」語法。

這是你的第一個代碼塊應該是什麼樣子:

$shorting = $conn->prepare("SELECT text,time FROM small WHERE active='0' ORDER BY time DESC LIMIT 10"); 
$shorting->execute(); 
while($obj = $shorting->fetch(PDO::FETCH_OBJ)){ 
    echo "<div id='lastnews_title'>"; 
    echo "<div> $obj->text </div>"; 
    echo "<div style='text-align:left'>"; 
    echo timeTonow($obj->time); 
    echo "</div>" 
} 

你缺少結束div標籤

我離開了PHP的標籤,因爲我認爲這是一個PHP文件和所有這些都被封裝在一組php標籤已經<php> </php>