PHP和Mysql可以对数据库进行简单的增删改查,本文介绍了新闻列表的后台管理。
Mysql数据库创建
创建一个新闻列表的数据库:
1. 查询数据库
1.1. 创建文件dbconfig.php,保存常量
<?php
define("HOST","localhost");
define("USER","root");
define("PASS","********");
define("DBNAME","news");
1.2. 创建入口文件index.html(连接数据库、查询数据)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>新闻后台管理系统</title>
</head>
<style type="text/css">
.wrapper {width: 1000px;margin: 20px auto;}
h2 {text-align: center;}
.add {margin-bottom: 20px;}
.add a {text-decoration: none;color: #fff;background-color: green;padding: 6px;border-radius: 5px;}
td {text-align: center;}
</style>
<body>
<div class="wrapper">
<h2>新闻后台管理系统</h2>
<div class="add">
<a href="addnews.html">增加新闻</a>
</div>
<table width="960" border="1">
<tr>
<th>ID</th>
<th>标题</th>
<th>关键字</th>
<th>作者</th>
<th>发布时间</th>
<th>内容</th>
<th>操作</th>
</tr>
<?php
// 1.导入配置文件
require "dbconfig.php";
// 2. 连接mysql
$link = @mysql_connect(HOST,USER,PASS)