find and replace phrase in complete database

<?php // Connect to your MySQL database. $hostname = "host"; $username = "username"; $password = "password"; $database = "database"; mysql_connect($hostname, $username, $password); // The find and replace strings. $find = "exampledomain.com"; $replace = "www.newdomain.org"; $loop = mysql_query(" SELECT concat('UPDATE ',table_schema,'.',table_name, ' SET ',column_name, '=replace(',column_name,', ''{$find}'', ''{$replace}'');') AS s FROM information_schema.columns WHERE table_schema = '{$database}'") or die ('Cant loop through dbfields: ' . mysql_error()); while ($query = mysql_fetch_assoc($loop)) { mysql_query($query['s']); } ?>
Used for moving a wordpress website from one to another server. Saved as a small script in /root of the new server.

From: http://stackoverflow.com/a/22358643/703882

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.