dsvs50005 2014-03-01 15:53
浏览 36
已采纳

如何使用phpfastcache?

this is my main query in index.php file

I am trying to cache this query with 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>

this is an example in phpfastcache site

// 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;

I write require_once("../phpfastcache/phpfastcache.php"); in my index.php

I dont know how to insert my query in this cache class?

sorry for bad english

  • 写回答

1条回答 默认 最新

  • dsajdgjadwqe3247382 2014-03-04 14:34
    关注

    you don't have a set of <php> tags surrounding this set of php statements

    $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)){
    

    this code doesn't look like it functions, and I think that is the point you are getting at here.

    you should study some of the basics of PHP. I know very Little about PHP and what you are trying to do, but I know that this is bad "php" grammar.

    this is what your first code block should look like:

    $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>"
    }
    

    you are missing an ending div tag

    I left out the php tags because I assume that this is a php document and that all of this is enclosed in a set of php tags already <php> </php>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。