php程序如何获取数据库信息生成静态页面

来源:百度知道 编辑:UC知道 时间:2024/05/21 09:10:48
php程序如何获取数据库信息生成静态页面
主要是提取数据库里的多条信息,循环不会弄。

一般都是用模版作。php处理完了写成文件。

一个思路:

<?php
$cache_file="abc.htm";
if (! file_exists($cache_file)){//重新生成文章
$out_str='';
//连接数据库,生成所有内容到变量$out_str里面
if ($fp=fopen($cache_file,'w')){fwrite($fp,$out_str); fclose($fp);}
}else $out_str=file_get_contents($cache_file);//取以前保存的文章内容

//输出前做一些处理:比如替换里面的日期等
echo $out_str;
?>

你是想和数据库结合的话,我这里有实现的例子:

//连接数据库
mysql_connect("$host","$user","$password");
mysql_select_db("$databasename");

//使用到的SQL语句
$query00 = "";
$result00 = mysql_query($query00);