Title: Multisite with Multiple DB
Last modified: August 21, 2016

---

# Multisite with Multiple DB

 *  [wlpdrpat](https://wordpress.org/support/users/wlpdrpat/)
 * (@wlpdrpat)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/multisite-with-multiple-db/)
 * Hi,
 * I found you plugin from another support thread where it suggested that I could
   use your plugin to make changes on a multisite installation across all sites.
 * When I try to search for a known value that exists in almost all of our sites
   databases I get an error that says:
 * Sorry, searchterm is not found in this Database(mydatabase)!
 * Where “searchterm” is the value I searched and “mydatabase” is the original database
   name before we started using a multi-database configuration. Our databases are
   now named: mydatabase_global, mydatabase_0 to mydatabase_9 and mydatabase_a to
   mydatabase_f.
 * I use many other plugins that have no problem with the multi-database configuration,
   so I was fairly surprised that this appears to be an issue.
 * I am going to review the coding of your plugin to see if I can find the issue.
   If I discover the issue and if I am able to resolve it I will let you know.
 * Pat
 * [http://wordpress.org/extend/plugins/search-and-replace/](http://wordpress.org/extend/plugins/search-and-replace/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [wlpdrpat](https://wordpress.org/support/users/wlpdrpat/)
 * (@wlpdrpat)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/multisite-with-multiple-db/#post-3742540)
 * Just as a further note:
 * I tried using the Search in Content and received the following error:
 * Looking @ post content …
    … in table posts, field post_content: The inquiry could
   not be implemented: Table ‘mydatabase_global.wp_1_posts’ doesn’t exist
 * I think this should make it more clear that your plugin is currently not compatible
   with a multi-database configuration.
 * As your plugin is designed to search and replace in the database; it makes sense
   that it would work with multisite if multisite is using a single db. However,
   to work with a multidb configuration it should first check if multidb is being
   used and how many db are being used: 16, 256, or 4096 (these are the most common).
   Then if multidb is used if you are doing a global search and replace it would
   have to go through each database making the search and replace.
 * I have a fix database plugin that I customized to make it work using something
   like the following:
 *     ```
       function fdb_fix_database($targetdb = "") {
       		global $wpdb;
       		global $blog_id;
       				set_time_limit(1800);
       		if(empty($blog_id) || ($blog_id == 1) || is_network_admin()) {
       			$dataset = $targetdb;
       		}
       		else
       		{
       			$hash_value = md5($blog_id);
       			if (DB_SCALING == '16'){
       				$dataset = substr($hash_value, 0, 1);
       			} else if (DB_SCALING == '256'){
       				$dataset = substr($hash_value, 0, 2);
       			} else if (DB_SCALING == '4096'){
       				$dataset = substr($hash_value, 0, 3);
       			} else {
       				$dataset = substr($hash_value, 0, 1);
       			}
       		}
       			global $db_servers;
       			$server = $db_servers[$dataset][0];
       			$dbcon = @mysql_connect( $server['lhost'], $server['user'], $server['password'],true);
   
       			if ( !@mysql_select_db( $server['name'] , $dbcon ) )
       			{
       				echo "error";
       			}
   
       			if (empty($blog_id) || ($blog_id == 1) || is_network_admin())
       			{
       			   $tablelist = getresult(@mysql_query( "show tables ", $dbcon ));
       			}
       			else
       			{
       			   $tablelist = getresult(@mysql_query( "show tables from " . $server['name'] . " like '%\_".$blog_id."\_%'", $dbcon ));
       			}
   
       						foreach ($tablelist as $tar) {
       							$tablename = $tar[0];
       ```
   
 * Sorry if it is a bit messy but this should give you the idea.
 * It would be fantastic if you also added a Network Admin page so that you could
   search and replace globally on a multisite install and then the normal search
   and replace page could be used for search and replace on a single site.
 * Pat
 *  [Sam](https://wordpress.org/support/users/sdominique/)
 * (@sdominique)
 * [13 years ago](https://wordpress.org/support/topic/multisite-with-multiple-db/#post-3742959)
 * Joining this thread. I’ll love if it if this plugin can work with multi db set
   ups.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Multisite with Multiple DB’ is closed to new replies.

 * ![](https://ps.w.org/search-and-replace/assets/icon-256x256.png?rev=1776844)
 * [Search & Replace](https://wordpress.org/plugins/search-and-replace/)
 * [Support Threads](https://wordpress.org/support/plugin/search-and-replace/)
 * [Active Topics](https://wordpress.org/support/plugin/search-and-replace/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/search-and-replace/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/search-and-replace/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Sam](https://wordpress.org/support/users/sdominique/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/multisite-with-multiple-db/#post-3742959)
 * Status: not resolved