Replace string on db (PHP)

  1. First take a db dump (check this)!
  2. Then use this (at your own risk!)
<?php

$file = "db-dump.sql";

$replace = array(
	"http://ratikal.gr" => "https://ratikal.gr",
);	

$contents = file_get_contents($file);

echo "look in: $file\n";

foreach ($replace as $search_str => $replace_str)
{
	echo " for: $search_str\n replace with: $replace_str\n";
	echo " before: ".substr_count($contents, $search_str); 
	
	$contents = str_replace($search_str, $replace_str, $contents);

	echo "\n after: ".substr_count($contents, $search_str)."\n\n"; 
}

file_put_contents("replaced-$file", $contents);

die("ok");

3. Throw the replaced-db-dump.sql back to db!