In the default.settings.php,it says

* To have all database names prefixed, set $db_prefix as a string:
*
* $db_prefix = 'main_';
*
* To provide prefixes for specific tables, set $db_prefix as an array.
* The array's keys are the table names and the values are the prefixes.
* The 'default' element holds the prefix for any tables not specified
* elsewhere in the array. Example:
*
* $db_prefix = array(
* 'default' => 'main_',
* 'users' => 'shared_',
* 'sessions' => 'shared_',
* 'role' => 'shared_',
* 'authmap' => 'shared_',
* );

And then,in includes/common.inc on line 486,the following code may cause a problem

// If the database prefix is being used by SimpleTest to run the tests in a copied
// database then set the user-agent header to the database prefix so that any
// calls to other Drupal pages will run the SimpleTest prefixed database. The
// user-agent is used to ensure that multiple testing sessions running at the
// same time won't interfere with each other as they would if the database
// prefix were stored statically in a file or database variable.
if (preg_match("/simpletest\d+/", $GLOBALS['db_prefix'], $matches)) {
$defaults['User-Agent'] = 'User-Agent: ' . $matches[0];
}

If I use an array defenition of the $db_prefix,it may cause an php waring as following every time i run cron.

warning: preg_match() expects parameter 2 to be string, array given in /srv/http/drupal/includes/common.inc on line 492.

I add a check whether the $db_prefix to avoid this warning,but i think this shoud have a better solution.

CommentFileSizeAuthor
#3 common - Kopie.inc_fix.diff609 bytesem_mah

Comments

bs’s picture

any fix? We face similar problem in multi-site setup. some times it seems to be working and some times won't.

bs’s picture

this is my fix for custom function:

global $db_prefix;
    if (is_array($db_prefix)){
        if (array_key_exists($table, $db_prefix)){
            $table_prefix = $db_prefix[$table];
        }else {
            $table_prefix = $db_prefix['default'];
        }
    }else {
        $table_prefix = $db_prefix;
    }
em_mah’s picture

StatusFileSize
new609 bytes

Hi,

the most simplest fix would be to check, whether $GLOBALS['db_prefix'] is a string. Since testing should normally not require to split tableprefixes, this seems accurat to me.

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.