gpt4 book ai didi

php - 在一个 PHP 文件中运行 2 个 MySQL 更新查询

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:45 25 4
gpt4 key购买 nike

我试着跑

// Create connection
$conn = new mysqli($servername,$username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE pm_videos SET `description` = REPLACE( `description` ,'Facebook', '')";
$sql = "UPDATE pm_videos SET `description` = REPLACE( `description` ,'Twitter', '')";

if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();

但只有推特会被取代。我是 PHP 的新手。也许有人可以帮我解决这个问题。谢谢。

最佳答案

$conn->query($sql) 语句运行您的查询。在运行它之前,您正在覆盖第一个 $sql(Facebook 的那个)。你会想做类似的事情

$sql = "UPDATE pm_videos SET `description` = REPLACE(  `description` ,'Facebook',  '')";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully with Facebook";
} else {
echo "Error updating record: " . $conn->error;
}
$sql = "UPDATE pm_videos SET `description` = REPLACE( `description` ,'Twitter', '')";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully with Twitter";
} else {
echo "Error updating record: " . $conn->error;
}

关于php - 在一个 PHP 文件中运行 2 个 MySQL 更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34568830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com