《2019年3月2日》【连续513天】
标题:mysql案例delete;
内容:
<?php
// 接收要删除的数据 ID
if (empty($_GET['id'])) {
exit('<h1>必须传入指定参数</h1>');
}
$id = $_GET['id']; // => 1,2,3
// 1. 建立连接
$conn = mysqli_connect('localhost', 'root', '123456', 'test');
if (!$conn) {
exit('<h1>连接数据库失败</h1>');
}
// 2. 开始查询
$query = mysqli_query($conn, 'delete from users where id in (' . $id . ');');
if (!$query) {
exit('<h1>查询数据失败</h1>');
}
$affected_rows = mysqli_affected_rows($conn);
if ($affected_rows <= 0) {
exit('<h1>删除失败</h1>');
}
header('Location: index.php');
本文详细介绍了一种使用PHP批量删除MySQL数据库中指定ID记录的方法。通过接收URL参数中的ID,构建SQL语句并执行删除操作,最后返回操作结果。
1295

被折叠的 条评论
为什么被折叠?



