如果返回200但数据库没有任何动作,可能是因为请求没有正确执行SQL语句。我们可以通过以下步骤进行调试和修复:
update_sql.php
中添加错误处理,以便查看是否有SQL错误。以下是更新后的代码,增加了错误处理和调试信息:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$searchTerm = $_POST['searchTerm'];
$replaceTerm = $_POST['replaceTerm'];
// 创建多个cURL句柄
$urls = [
"http://yourdomain.com/update_sql.php?type=title&searchTerm=" . urlencode($searchTerm) . "&replaceTerm=" . urlencode($replaceTerm),
"http://yourdomain.com/update_sql.php?type=content&searchTerm=" . urlencode($searchTerm) . "&replaceTerm=" . urlencode($replaceTerm),
"http://yourdomain.com/update_sql.php?type=content_fmt&searchTerm=" . urlencode($searchTerm) . "&replaceTerm=" . urlencode($replaceTerm)
];
$multiHandle = curl_multi_init();
$curlHandles = [];
// 初始化cURL句柄
foreach ($urls as $url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curlHandles[] = $curl;
curl_multi_add_handle($multiHandle, $curl);
}
// 执行所有cURL句柄
do {
$status = curl_multi_exec($multiHandle, $active);
curl_multi_select($multiHandle);
} while ($active && $status == CURLM_CALL_MULTI_PERFORM);
// 移除句柄并关闭
foreach ($curlHandles as $curl) {
curl_multi_remove_handle($multiHandle, $curl);
curl_close($curl);
}
curl_multi_close($multiHandle);
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>替换词</title>
</head>
<body>
<form method="post" action="">
<label for="searchTerm">替换前词:</label>
<input type="text" id="searchTerm" name="searchTerm" value="王bao强" required>
<br>
<label for="replaceTerm">替换后词:</label>
<input type="text" id="replaceTerm" name="replaceTerm" value="王宝强" required>
<br>
<button type="submit">提交</button>
<button type="reset">清空</button>
</form>
</body>
</html>
update_sql.php
):<?php
// 数据库连接
$conn = new mysqli("localhost", "username", "password", "database");
// 检查连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 获取参数
$type = $_GET['type'];
$searchTerm = $_GET['searchTerm'];
$replaceTerm = $_GET['replaceTerm'];
// 根据类型执行不同的更新
if ($type === 'title') {
$sql = "UPDATE fa_ask_question SET title = REPLACE(title, '$searchTerm', '$replaceTerm') WHERE title LIKE '%$searchTerm%'";
} elseif ($type === 'content') {
$sql = "UPDATE fa_ask_question SET content = REPLACE(content, '$searchTerm', '$replaceTerm') WHERE content LIKE '%$searchTerm%'";
} elseif ($type === 'content_fmt') {
$sql = "UPDATE fa_ask_question SET content_fmt = REPLACE(content_fmt, '$searchTerm', '$replaceTerm') WHERE content_fmt LIKE '%$searchTerm%'";
}
// 执行更新
if ($conn->query($sql) === TRUE) {
echo "更新成功";
} else {
echo "错误: " . $sql . "<br>" . $conn->error; // 输出错误信息
}
// 关闭连接
$conn->close();
?>
update_sql.php
中添加了错误处理,输出SQL语句和错误信息,以便调试。yourdomain.com
替换为您的实际域名。fa_ask_question
表和字段存在,并且有数据可以更新。通过这些修改,您应该能够看到更详细的错误信息,从而帮助您解决问题。