Database Search and Replace Script in PHP

Search Replace DB version 3.1.0 is a user-friendly, front-end tool for developers, that allows you to carry out database wide search/replace actions, that don't damage PHP serialized strings or objects.


It has come to our attention that some users have been leaving this script on their servers despite advice to the contrary. Due to the very real dangers it can present when used that way, we now ask that you complete a form where we make sure you’re aware of these risks in order to receive the download link. Do also carefully read the installation instructions below.

Please check your spam folder for the download link before you email us for support. If you are still experiencing problems, email us politely with your query.


Download the script from the link you received by email, and install it to a secret folder with an obfuscated name. Your server should also not be set to provide directory lists.

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


Do not install Search Replace DB to the root folder or in WP’s own folder hierarchy or you risk all sorts of potential problems. Just don’t. It must run in its own folder.

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.


The code is supplied under the GPL V3 and is fully open source. Do be aware that this means people can change this code and offer it up, and that other versions may be worse… or better. It is code for developers, by developers, and you should only use code from sources you trust.


Please beware of adverts below that offer a download button, but adverts do allow us to partly cover the cost of running this project.


Where do I install the unzipped files?

In a directory on your webserver. It can be an httpauth protected folder if it’s a public facing webserver.

I heard this script is insecure. Is it really?

Yes – it’s a development tool, not something you should be putting on production servers. If you do put it on a production server be really careful. We’re trying to work out ways of protecting users further, because it turns out that this tool is being recommend by webhosts around the world, but too often to quite naive users who don’t really understand the risks.

I get an error 2: Class __PHP_Incomplete_Class has no unserializer

This is a common error and generally comes up with users of Yoast plugins, but also some others. It’s something we’re aware of. In the vast majority of cases everything is fine. You could try running the script from a different PHP install – there is no reason why you can’t have a pipe to a production database and connect to it from your workstation, for example. A little more detail is on our github repository.


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):

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.


We’d love to get contributions, bug reports and more on the Search Replace DB github repository. Please come on over – you’ll be more than welcome but you will need to request access by emailing


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.

1,562 responses to “Database Search and Replace Script in PHP

  1. I am using Visual Composer to create my sites, but it seems that the script is not replacing links that I created inside Visual Composer. Do I have to change them manually?

    1. Hi, I’m having the exact same problem with my site, I’m using Velvet Blues Update URLs plugin and it replaces all links in my site except for the ones in buttons I’ve created with Visual Composer of which there are quite a few. I’m desperately trying to find a solution as manually changing the links is quite a mission – did you find a solution?

      1. Same problem here! Do you found a solution?

  2. Hi, I don’t have too much experience with databases and I’m having a difficult time with what this seems to solve. How do I access the folder from my browser exactly?

  3. Hi,

    The file “srdb.class.php” appears to be missing from the package today

    Thanks for the script.

    1. I see it in the src/ directory.
      But get this error when running from the command line:

      Warning: require_once(/home/xxxx/bin/srdb.class.php): failed to open stream: No such file or directory in /home/xxxx/bin/srdb.cli.php on line 14

      Fatal error: require_once(): Failed opening required ‘/home/xxxx/bin/srdb.class.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/xxxx/bin/srdb.cli.php on line 14

      1. I’ve temporarily copied src/srdb.class.php one directory up to get it going

    2. Apologies – a change got released by accident. Should be fine now.

  4. Hi
    Thanks for that tool!!!
    I’ve updated a WP installation with Avada theme and got the following message 8 times (second update from .dev. to .staging):

    2:Class__PHP_Incomplete_Class has no unserializer in /home/glppanar/www/ in line 735

    But everything looks ok …
    Any idea what happen?
    Thank you

  5. What a great tool! So nice of you to make this available for free. It works really well. Thank-you so much!

  6. Why are you base64’ing code in your script? mod_security is flagging it as malicious. Seems to be a new issue.

    1. It’s not code that’s base 64’d but images. The idea is to show branding without fetching it from a server. To be fair, given that it’s no longer a single file application that could now be included in the checkout. So I’ll add a case to fix that. Thanks for highlighting the issue.

      1. Thanks! Looking forward to a fix!

  7. Hi, great tool!

    Question, if you have a dump, can we still use this script?

    1. No – it works against running databases. So you can load the dump into a new DB and then run the script, but not run it against the text.

  8. We really love this tool ! One click and all entries are changed easily.

    We appreciate your hard work interconnectit team !

  9. ¡EXCELENTE! Una magnífica herramienta que me ayudó a solucionar el problema que tenía un cliente por una base de datos con urls diferentes. Son unos cracks! Muchas gracias. Saludos desde México

  10. it working great. thanks for the tool

Comments are closed.