<?php //数据库配置信息 $db_host = "localhost"; $db_user = "123456"; $db_pwd = "123456"; $db_name = "shujuku"; $db_prefix = "01_"; //数据表的前缀 //连接MysSQL数据库 $link = @mysql_connect($db_host, $db_user, $db_pwd); if(!$link) { exit("数据库连接失败!"); }else{ //echo "数据库连接成功"; } //选择当前数据库 if(!mysql_select_db($db_name, $link)) { exit("选择数据库".$db_name."失败"); }else{ //echo "数据库".$db_name."连接成功"; } //设置返回数据的字符集 mysql_query("set names utf8"); //查询数据 //$sql = "SELECT * FROM {$db_prefix}news ORDER BY id DESC"; $sql = "SELECT id,title,author,content,createtime FROM {$db_prefix}news ORDER BY id DESC"; $result = mysql_query($sql); //echo $result; ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>新闻列表</title> </head> <body> <table width="800px" border="1" style="border-collapse: collapse;"> <thead> <th>编号</th> <th>标题</th> <th>作者</th> <th>内容</th> <th>创建时间</th> </thead> <?php while($row = mysql_fetch_row($result)) { // print_r($row); //打印输出,测试使用 // exit(); //终止程序 ?> <tr> <td align="center"><?php echo $row[0]; ?></td> <td align="center"><?php echo $row[1]; ?></td> <td align="center"><?php echo $row[2]; ?></td> <td align="center"><?php echo $row[3]; ?></td> <td align="center"><?php echo $row[4]; ?></td> </tr> <?php } ?> </table> </body> </html>