php网站查看数据库的方法:
连接数据库代码:<?php
define("DB_HOST","localhost");
define("DB_USER","root");
define("DB_PWD","");
define("DB_NAME","wordpress4");
$conn = @mysql_connect(DB_HOST,DB_USER,DB_PWD) or die("连接服务器出错:".mysql_error());
@mysql_select_db(DB_NAME) or die("连接数据库出错:".mysql_error());
@mysql_query('SET NAMES UTF8');
?>
读取数据库信息代码:$result = mysql_query("select * from wp_wf order by timer02 desc limit 0,50");//获取最新50条数
while($row = mysql_fetch_array($result))//转成数组,且返回第一条数据,当不是一个对象时候退出
{
echo '
数据详情'.$row['number02'].'
str_ireplace(",","
",$row['datar02']).'
}
关闭数据库代码:mysql_close($conn);
三段代码结合在一起,就可以实现 PHP读取数据库并显示到网站前台。代码如下:<?php
require "conn.php";//连接数据库
$result = mysql_query("select * from wp_kaijiangwf order by timer02 desc limit 0,50");//最新50条数
while($row = mysql_fetch_array($result))//转成数组,且返回第一条数据,当不是一个对象时候退出
{
echo '
数据详情'.$row['number02'].'
str_ireplace(",","
",$row['datar02']).'
}
mysql_close($conn);// 关闭数据库
?>