缓存文学

//html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><-title-></title>
</head>
<body>
<h2><-title-></h2>
<hr>
<div>日期:<-date->作者:<-author-></div>
<div><-contents-></div>
<div>评论数:<span id="s1"></span>点击数:<span id="s2"></span></div>
<script src="jquery.js"></script>
<script>
$(function(){
$.get('../gethitts.php',{'id':<-id->},function(txt){
$('s1').html(txt);
},'text',true);
$.get('../getcommentcount.php',{'id':<-id->},function(txt){
$('s2').html(txt);
},'text',true);
})
</script>
</body>
</html>

//php+PDO

(

<?php
set_time_limit(0);
ob_start();
echo str_repeat('',4000);
ob_end_flush();
flush();
$pdo = new PDO('mysql:host=localhost;dbname=create','root','root');
$pdo->exec('set names utf8');
$sql = "select * from zjy_article_cate order by id asc";

$temp = file_get_contents('newhtml.html');

$rs = $pdo->query($sql);

while($row=$rs->fetch(PDO::FETCH_ASSOC))
{
$con=str_replace('<-title->',$row['name_1'],$temp);
$con=str_replace('<-date->',date('Y-m-d',$row['addtime']),$con);
$con=str_replace('<-author->',$row['author'],$con);
$con=str_replace('<-contents->',$row['contents'],$con);
$con=str_replace('<-hitts->',$row['hitts'],$con);
$con=str_replace('<-id->',$row['id'],$con);

file_put_contents('html/'.$row['id'].'.html',$con);
echo 'html/'.$row['id'].'.html<br>';
ob_flush();
flush();
sleep(1);

}
?>

<?php
$id=$_GET['id'];
$pdo = new PDO('mysql:host=localhost;dbname=create','root','root');
$pdo->exec('set names utf8');
$sql = "select hitts from zjy_article_cate where id=$id";

$rs = $pdo->query($sql);
$row = $rs->fetch();
$sql = "update zjy_article_cate set hitts=hitts+1 where id=$id";
$pdo->exec($sql);
exit($row['hitts']);

?>

//mysql数据库

 

 )

posted @ 2016-12-21 20:44  jinyucd  阅读(113)  评论(0编辑  收藏  举报