Download

Database Search and Replace Script in PHP

Search Replace DB version 3.1.0 allows you to carry out database wide search/replace actions that don’t damage PHP serialized strings or objects with a user friendly interface and experience.

Installation & Use

WPPP-advert-mpu
search-replace-mobile-screenshot Now acts like a web app!

Please read all instructions and familiarise yourself with the risks of using this tool first, downloading of this tool signifies your acceptance of the risks and problems associated with the script.

To use the script, download the zip file from below, extract the folder called search-replace-db-master (assuming you are using the 3.1.0 version), renaming it to something secret of your choosing, upload it via FTP, SFTP or SCP to your web server’s public facing directory, then navigate to that folder in your browser. The script will automatically attempt to find and populate the database field but you must check that the details are correct and that it is for the database you wish to carry out a search/replace operation on.

A typical WP install with this script would have the folders as follows:

/your-secret-search-replace-folder
/wp-admin
/wp-content
/wp-includes

IMPORTANT: Do not place the contents of the script’s folder into your root directory! It isn’t designed or supposed to run from there and, if you use the auto-delete functionality, it will delete everything in that folder, which could wipe out your site. I can’t stress this enough. If this isn’t clear for you it would be a good idea to seek expert help – hire a developer for an hour or two to come and do this for you.

To see how you can use this tool to aid migrations, check out our article on WordPress migrations or visit the WP Tuts+ article that mentions this script.

If you are in any doubt whatsoever about how to use this standalone script, then please consider getting an expert in. It’s a really powerful bit of code that if used badly can damage a WP install beyond repair. If you want help, get in somebody like us, for example, or any of the other great guys listed over at CodePoet.

IMPORTANT: This code is supplied with no warranty or support implied. You use it entirely at your own risk. The code is licensed under the GPL V3 and you should be aware of its limitations and how they affect you and your use of this code. Please also read the instructions and warnings provided and always take a verified backup of your database before starting.

Download v 3.1.0

Older server? Try v 2.1.0

Ad

Please beware of adverts that offer a download button!


Why is there an ad here? Because the small amount of revenue this advert might bring us helps to go towards the not inconsiderable cost of running the search/replace project. It’s in the order of thousands of pounds, believe it or not, and we’re working to a new version with better compatibility and this will help.

Changelog:

Test 20160504:
* Version 3.1.0 (Web UI and CLI versions) tested against PHP 7.0.6 and functioned correctly.
* Version 2.1.0 confirmed to not work with PHP 7.0.6 but is kept for use on older servers.

Version 3.1.0:
* Safety checks to prevent deletion when installed incorrectly. However, you should still take care when dealing with files on your server.
* JavaScript popup confirmation on ‘Delete Me’.
* Port number option in both the GUI and CLI. Use –port nnn to set a non-default MySQL port.
* Fixed Drupal bootstrap behaviour. Start up of script uses Drupal data as guide, no longer relies on a full successful Drupal initialisation before script will allow you to proceed.
* Driver selection improved so that PDO will be attempted first if PDO+mysql is available, with mysqli being used as a fallback. This fixes ‘driver not found’ errors.
* Removed mysql_ functions and replaced with mysqli_.
* Improved JS preview overlay for dry runs. This means that the right pane will always show the most accurate data possible. If serialised strings are present, highlights are not displayed.

Version 3.0.0:
* Major overhaul
* Multibyte string replacements
* UI completely redesigned
* Removed all links from script until ‘delete’ has been clicked to avoid security risk from our access logs
* Search replace functionality moved to it’s own separate class
* Replacements done table by table to avoid timeouts
* Convert tables to InnoDB
* Convert tables to utf8_unicode_ci
* Use PDO if available
* Preview/view changes
* Optionally use preg_replace()
* Scripts bootstraps WordPress/Drupal to avoid issues with unknown serialised objects/classes
* Added marketing stuff to deleted screen (sorry but we’re running a business!)

Version 2.2.0 (never formally released but patched into v3.0.0):
* Added remove script patch from David Anderson (wordshell.net)
* Added ability to replace strings with nothing
* Copy changes
* Added code to recursive_unserialize_replace to deal with objects not just arrays. This was submitted by Tina Matter.
* ToDo: Test object handling. Not sure how it will cope with object in the db created with classes that don’t exist in anything but the base PHP.

For changes prior to v2.2.0 please refer to index.php where you will find a complete changelog. You can also browse the project on github.

To Be Done

Ensure UTF8 encoding is enforced (see comments). Added in v2.1.0
Self deletion or security system to prevent accidental security risks. Added in v3.0.0
Release CLI version for use on non-WP sites, or for other purposes (already supports use on any MySQL DB.) Added in v3.0.0
Change to GPL V3. Added in v3.0.0
Eliminate warnings and remove deprecated function calls. Added in v2.1.0
Add facility to subscribe to interconnect/it Newsletter. Added in v3.0.0
Confirm deletion has actually happened.
Add old versions for download to this page.

Contributions

We’d love to get contributions, bug reports and more on the Search Replace DB public github repository. Please come on over – you’ll be more than welcome!

Donations

We’ve been asked a lot in the comments box below about accepting donations. But you can’t believe what a headache that is from an accounting and tax perspective.

Consequently all we can say is that if you wish to you can buy a personal gift for the key developers from one of the wishlists below – especially given that it’s a spare time project. If others who have contributed wish to provide us their wishlist links then we’d be more than happy to add them.

David Coveney is the project lead.
James Whitehead added the nice UI in v2.0+.
Robert O’Rourke created version 3.0.0 with its AJAX UI and massive improvements.

Comments
  • Julian 9 / Jun / 2016 at 1:37 pm

    Great tool indeed !
    Only one problem: how to seek more than 20 items in preview ?
    Pagination ?

    Thank yoi !

    Julian

    • David Coveney
      David Coveney 13 / Jun / 2016 at 10:56 am

      It’s a performance and size limitation – the preview is there to help a little, but we can’t really cover everything, but again, we’ll think about what can be done to improve the experience in the future.

  • Kevin 7 / Jun / 2016 at 10:51 pm

    Ist it possible to run this script on an Amazon AWS EC2 instance?

    • Mim McNeela
      Mim McNeela 8 / Jun / 2016 at 5:36 pm

      Hi Kevin. As long as it’s PHP and MySQL (or compatible) it should work.

  • T,Tod. 4 / Jun / 2016 at 8:00 am

    for my local purposes (for 1-20MB SQL files),
    i have created script myself, and it helps me much:
    http://protectpages.com/software/WordpressMigrator.php

  • Anne 31 / May / 2016 at 10:13 am

    Hi David,

    I found a similar error.

    “An browser-popup appears with the message:

    The script encountered an error while running an AJAX request. If you are using your hosts file to map a domain try browsing via the IP adress directly. If you are still running into problems we recommend trying the CLI script bundled with this package. See the README for details.”

    In the apache error log I found this:
    “Got error ‘PHP message: PHP Fatal error: Call to undefined function mb_regex_encoding() in /var/www/html/search-replace-db-master/srdb.class.php on line 279” Followed by a stack trace.

    I found out that the PHP module ‘mbstring’ was not installed, so I installed it and now it runs without any errors.
    I’m running PHP 5.6 on a VM set up by PuPHPet (https://puphpet.com). I can send you my config files if you like.

    Hope this helps 🙂

    Best
    Anne

    • David Coveney
      David Coveney 2 / Jun / 2016 at 12:05 pm

      Thanks Anne,

      Although mbstring is very commonly installed on PHP installations it’s not guaranteed. If you have a problem with this script it’s always a good idea to check error logs, and it’s amazing how few actual error messages we ever receive!

      I’ll have to have a think about building a list of pre-requisites for the tool.

  • Mathuseo 24 / May / 2016 at 6:11 pm

    David Coveney
    Thanks Lucio – not seen this. Can you send more information to help us track this down, such as PHP version and similar?

    Hi David, I found the same (probally) error. In my case I’ve got the message:

    The dry-run option was selected. No replacements will be made.
    The table “blabla_cf7dbplugin_submits” has no primary key. Changes will have to made manually.

    An browser-popup appears with the message:

    The script encountered an error while running an AJAX request. If you are using your hosts file to map a domain try browsing via the IP adress directly. If you are still running into problems we recommend trying the CLI script bundled with this package. See the README for details.

    Any idea what to do? If you need further information, please contact me. I can send you screenshots or give you access to my website, that you can check for yourself what wents wrong.

    Best,
    Mathuseo

    • David Coveney
      David Coveney 26 / May / 2016 at 12:22 pm

      The AJAX error could well be the result of the PHP process timing out on servers that don’t allow the time to be extended and where a search/replace operation on one particular table has taken a long time.

      You may need to use the CLI version of the script. Chances are that the run has worked up to a point. You can retry, or do a table at a time and see what happens.

      However, we’ll see if we can recreate this problem next time we put some development time into the script.

      • Lee 3 / Jul / 2016 at 8:03 pm

        I’ve seen this happen a couple of times. Clearing the web browser cache seems to fix it. I notice it happens more often when one WordPress site’s database has been updated and another WP site within the same server space is about to have its database updated (but fails due to the AJAX error). Could be a cookie issue.

  • Lucio 22 / May / 2016 at 8:29 pm

    great tool thanks, I use this regularly. However I’ve found a possible bug, here is the action output of a live run on a database:

    The table “asso_ucontext4a_click_log” has no primary key. Changes will have to be made manually.
    The table “asso_translations” has no primary key. Changes will have to be made manually.
    2: Class __PHP_Incomplete_Class has no unserializer in /home/lucio/virtualbit/progetti/workspace/netbeans/assodigitale/wp/qpla/srdb.class.php on line 735

    last line repeats several times.

    Using version 3.1 on current Debian sid amd64.

    • David Coveney
      David Coveney 23 / May / 2016 at 3:16 pm

      Thanks Lucio – not seen this. Can you send more information to help us track this down, such as PHP version and similar?

  • […] To swap values using the interconnect/it Search and Replace script: […]

  • Miguel 19 / May / 2016 at 2:39 pm

    i just upload this to mi host or i have to do something more?

  • Patrick 13 / May / 2016 at 4:12 pm

    Any chance of table conversion to XtraDB?

    • Mim McNeela
      Mim 16 / May / 2016 at 2:05 pm

      Hi Patrick

      We’ve opened a case and put it into the backlog for future consideration when we come to release a new version.

  • How to Move WordPress to a New Server? 5 / May / 2016 at 6:36 pm

    […] not a text editor and change every instance of the local URL to the remote one. You can use SEARCH REPLACE DB for this, which should be installed in the root folder of your WP install for best results. In […]

  • Henry 4 / May / 2016 at 4:07 am

    Hi there, I have extract and rename the folder in my public_html directory. When I try to access the folder using domain.com.my/foldername, it says page not found. Did I made a mistake?

    • David Coveney
      David Coveney 4 / May / 2016 at 4:00 pm

      Should work, but maybe you have some things blocking the folder you created – check .htaccess and similar. Also, you may need to navigate directly to the file.

      • Henry 10 / May / 2016 at 12:16 am

        Hi David,
        I tried in my localhost, the url can work, but in my server, i need to insert /index.php after the folder name. This is what I get from the server support. Hope it helps for someone who encounter the same problem with me.

  • AG 2 / May / 2016 at 11:43 pm

    Hi,

    I really like the idea what it does but I never had success with this.
    I always gives me the AJAX error and then when I try from command line it gives me the bellow error…

    PHP Fatal error: Call to undefined function mb_regex_encoding() in /var/www/html//Search-Replace-DB-master/srdb.class.php on line 279

    Can someone suggest where am I going wrong?

    • David Coveney
      David Coveney 4 / May / 2016 at 4:02 pm

      Looks like your server doesn’t support multibyte. When we review a future release we can test for this and act appropriately.

    • Some Helper 4 / May / 2016 at 11:02 pm

      Make sure you have php mbstring module
      yum install php56-mcrypt php56-mbstring php56-cli

  • Asaf 2 / May / 2016 at 9:20 am

    Hi! great tool! been using it for a few years (the older versions).
    now started to work with the new 3.1 ver and it works fine with relatively new installations of WP, however when I try to use it with a site that has WP 3.3.1 i get these errors:

    Fatal error: Call to a member function set_404() on a non-object in /home../wp-includes/class-wp.php on line 484
    Could not bootstrap environment.
    Fatal error in /home../wp-includes/class-wp.php, line 484. Call to a member function set_404() on a non-object

    the DB details are not filled in automatically, and when I try to fill them out and hit “update details” I get the following error:
    The script encountered an error while running an AJAX request.

    help anyone?

  • JJ 29 / Apr / 2016 at 5:00 pm

    I’ve installed this in /Search-Replace-DB-master/ directory in the WordPress root. shows error SQLSTATE[HY000] [2002] No such file or directory.
    Underneath shows the correct Name/User/Pass/Host/Port(3306)

  • […] Database Search and Replace Script in PHP […]

  • Migrate WordPress Site To SSL 20 / Apr / 2016 at 4:11 pm

    […] time. A few years back, while working on a customer data migration, I came across a useful tool on Interconnect IT’s website. This tools was called “The Serialized PHP Search and Replace Tool” but has since been […]

  • Carl 19 / Apr / 2016 at 4:10 pm

    This is a great tool that we use for every website migration. However, now PHP 7 comes available, it seems that it doesn’t work good nymore. I get a blank screen on step 3.

    • Florian 2 / May / 2016 at 7:54 am

      Hi Carl did you found any solution to it?

    • David Coveney
      David Coveney 4 / May / 2016 at 4:03 pm

      Looks like you’re using v2.1.0? That indeed doesn’t work on PHP 7. I’ll add a notice here to that effect.

      Try 3.1.0 instead – it works fine on PHP 7.

  • […] This is the second hardest part of the migration. You’ll either need to use wp-cli search and replace or a visual search and replace tool like this one. […]

  • […] Hopefully, there are some great solutions that will do this for you. There is a good service from Interconnectit that finds and replaces the database links from your WordPress […]

  • How to Migrate a WordPress Site 13 / Apr / 2016 at 6:15 am

    […]  Search and Replace for WordPress Databases Script to safely update the file paths (this script is awesome – it runs almost instantly). This […]

  • Lucio 8 / Apr / 2016 at 9:42 am

    Thanks great tool! It would be perfect if it could be called from a bash script though… (’cause I have a base wordpress install with my configured plugins I clone each time I need a new website).

  • phil 30 / Mar / 2016 at 2:29 am

    Thanks so much for this – brilliant

  • Vijesh 10 / Mar / 2016 at 10:08 am

    I had wasted lots of hours to find such solutions for WP. Used several so-called search and replaced plugins but none of them would replace the lines of URLs, but your simple solution script did this job perfectly within 2 minutes. Well done guys for making such script.

  • Noman Riffat 9 / Mar / 2016 at 1:49 pm

    Wow, saved a lot of time. Thanks you so much for an awesome tool. But this tool is easily searchable using google dorks so better make it password protected

    • David Coveney
      David Coveney 18 / Mar / 2016 at 5:41 pm

      Indeed! You can protect the folder if you so choose. I’m actually wondering if we could generate the .zip with an included randomly built .htaccess file in it. Hmmmm… would need to charge for it though as the server resource to do the building would climb a fair bit. Still… a good idea.

      • Max 9 / Apr / 2016 at 9:16 am

        I should let you know that I have been using this script for around 4 years now. We are talking about cloning of 100s of WP sites on to different domains. In 4 years, I have encountered an issue only once where I hit timeout limits before the replace could execute. I can safely say that I have used your script more than any other user that has ever visited this page.

    • Max 9 / Apr / 2016 at 9:13 am

      The idea is to use this script and delete it right away. Why would you continue to have it in your site’s public facing directory once you are done with it? Just come back to this site and wget the download link again whenever you need it. Delete again once done.

  • Marc 4 / Mar / 2016 at 12:21 pm

    hi,

    when was the last update 3.1.0 (need the date)?

    the last version of 3 was crashing. but now i dont know the version (i worked with), because of the missing dates.

    thanks.

1 50 51 52 53 54 55