php语法如何结合mysql语法批量替换数据库中字符串

2024年12月05日 建站教程

如何结合php语法+mysql语法批量替换数据库中指定字符串,下面web建站小编给大家简单介绍一下具体实现代码!

代码如下:

<?php
$servername = "localhost";
$username = "用户名";
$password = "密码";
$dbname = "库名";
 
$conn = new mysqli($servername, $username, $password, $dbname);
 
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "UPDATE wp_table SET column1 = REPLACE(column1, 'html5', 'vuejs')";
 
if ($conn->query($sql) === TRUE) {
  echo "Records updated successfully";
} else {
  echo "Error updating records: " . $conn->error;
}
 
$conn->close();
?>

本文链接:http://so.lmcjl.com/news/18987/

展开阅读全文
相关内容