<?php
// Database connection details
$servername = "localhost";
$username = "root";
$password = "123";
$database = "staging_pestdefence";
// Array of table names to perform find and replace
$tables = array(
'_wp_rg_form_view',
'_wp_rg_lead',
'_wp_rg_lead_detail',
'_wp_rg_lead_detail_long',
'active_employees'
);
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// String to find and replace
$find = "http://staging.pestdefense.com";
$replace = "http://localhost/pestdefense";
// Loop through each table
// Assuming $conn is a valid database connection
// Loop through each table
foreach ($tables as $table) {
// Get the list of columns for the current table
$columns = array();
$result = $conn->query("SHOW COLUMNS FROM $table");
if ($result) {
while ($row = $result->fetch_assoc()) {
$columns[] = $row['Field'];
}
// Construct and execute the update query for each column
foreach ($columns as $column) {
// Check if the string to be replaced exists in the column
$checkSql = "SELECT COUNT(*) AS count FROM $table WHERE `$column` LIKE '%$find%'";
$checkResult = $conn->query($checkSql);
if ($checkResult) {
$countRow = $checkResult->fetch_assoc();
$rowCount = $countRow['count'];
if ($rowCount > 0) {
// Perform the replace if the string exists in the column
$sql = "UPDATE $table SET `$column` = REPLACE(`$column`, '$find', '$replace')";
// echo '<br>';
// echo $sql;
if ($conn->query($sql) === TRUE) {
echo '<br>';
echo "------------------Replaced values in $table.$column successfully<br>";
}...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.