我使用Smarty的時間多用這種設置:SQL查詢執行比智者
$smarty = new Smarty;
$smarty -> caching =3600;
$smarty -> compile_check =true;
$smarty -> compile_dir = 'theme/compile/';
$smarty -> config_dir = 'theme/libs/';
$smarty -> cache_dir = 'theme/cache/';
$smarty -> plugins_dir = 'theme/libs/plugins/';
$smarty->left_delimiter = '{';
$smarty->right_delimiter = '}';
$smarty -> clear_compiled_tpl();
我想編寫一個簡單的遊客使用此功能反擊:
function counter() {
$ip = $_SERVER['REMOTE_ADDR'];
$now = time();
$y1 = jgmdate("Y ", $now);
$y1 = (int) $y1;
$m1 = jgmdate("m", $now);
$m1 = (int) $m1;
$d1 = jgmdate("d", $now);
$d1 = (int) $d1;
$result3 = mysql_query("SELECT `times`,`id` FROM `stat_ip` where `IP`='$ip' AND `year`='$y1' AND `month`='$m1' AND `day`='$d1' ;");
unset($n3);
$n3 = (int) mysql_num_rows($result3);
echo $n3;
if ($n3 == 0) {
mysql_query("INSERT INTO `stat_ip` (`id` ,`IP` ,`year` ,`month` ,`day`) VALUES (NULL , '$ip', '$y1', '$m1', '$d1') ;");
} else if ($n3 == 1) {
$row3 = mysql_fetch_array($result3);
$s = (int) $row3['times'] + 1;
mysql_query("UPDATE `stat_ip` SET `times` = '$s' WHERE `id` = '".$row3['id']."' ;");
} else {
echo("error");
}
}
一切正常,但我的查詢這一行(大概所有查詢)的執行速度比時間更:
mysql_query("UPDATE `stat_ip` SET `times` = '$s' WHERE `id` = '".$row3['id']."' ;") ;
我認爲智者有someth要解決我的問題!
當我寫這篇文章的代碼:
$q=$smarty -> fetch('index.tpl');
查詢執行1次但是當我我的代碼更改爲:
$q=$smarty -> fetch('index.tpl');
echo $q;
或
$smarty -> display('index.tpl');
我的查詢執行超過一次!:(
瞭解更多信息:
http://www.smarty.net/forums/viewtopic.php?p=81161
如果實際輸出任何東西都是問題的原因,那不是聰明。你有一個過濾器的輸出緩衝區?或一些關機功能? – rodneyrehm 2012-07-16 20:15:34
我不明白你的意思 – 2012-07-17 06:51:43
你可以告訴我們index.tpl嗎? – sofl 2012-07-17 11:11:39