WordPress.org

Forums

Search & Replace
Multisite with Multiple DB (3 posts)

  1. wlpdrpat
    Member
    Posted 3 years ago #

    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/

  2. wlpdrpat
    Member
    Posted 3 years ago #

    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

  3. Atlanta
    Member
    Posted 3 years ago #

    Joining this thread. I'll love if it if this plugin can work with multi db set ups.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Search & Replace
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic