PHP+Mysql 实现数据库增删改查

本文详细介绍了如何使用PHP配合MySQL实现新闻列表的后台管理,包括数据库查询、新增新闻、删除和修改新闻的步骤。通过创建dbconfig.php配置文件,连接数据库并操作数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PHP和Mysql可以对数据库进行简单的增删改查,本文介绍了新闻列表的后台管理。

Mysql数据库创建

创建一个新闻列表的数据库:

o_360%e6%88%aa%e5%9b%be16680913888785.jpg

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.导入
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值