In settings I have:
$db_url['default'] = 'mysql://aaa';
$db_url['depletion'] = 'mysql://bbb';
In my custom module I have:
db_set_active('depletion');
.
.
.
db_set_active('default');
Even with nothing but commented out lines between them, I get the following error:
user error: Table 'local_aspo.blocks' doesn't exist
query: SELECT * FROM blocks WHERE status = 1 AND region = 0 ORDER BY weight, module in /.[snip]./database.mysql.inc on line 66.
I've tried removing the word 'default' from the 'default' db_set_active which makes no change.
BUT... when I change it to:
db_set_active('anything-else-but-default-or-depletion');
... it bizarrely works!
I'm using a two-day old 4.6RC. db_set_active is:
function db_set_active($name = 'default') {
global $db_url, $db_type, $active_db;
static $db_conns;
if (!isset($db_conns[$name])) {
// Initiate a new connection, using the named DB URL specified.
if (is_array($db_url)) {
$connect_url = array_key_exists($name, $db_url) ? $db_url[$name] : $db_url['default'];
}
else {
$connect_url = $db_url;
}
$db_type = substr($connect_url, 0, strpos($connect_url, '://'));
$handler = "includes/database.$db_type.inc";
if (is_file($handler)) {
include_once($handler);
}
else {
die('Unsupported database type');
}
$db_conns[$name] = db_connect($connect_url);
}
// Set the active connection.
$active_db = $db_conns[$name];
}
and in trying to debug, I did a print_r($db_conns) and got:
Array
(
[default] => Resource id #6
)Array
(
[default] => Resource id #6
[depletion] => Resource id #6
)
... which may be the problem somehow?
I'm still trying to get to grips with Drupal's ins-and-outs, so maybe someone more familiar can help me here. Its the first time I've tried a connection to an external database.
Thanks in advance for any pointers,
Jake
Comments
patch by chx
chx has released a patch, adding a simple TRUE argument to line 31 (in my copy) of database.mysql.inc. The line now reads:
$connection = mysql_connect($url['host'], $url['user'], $url['pass'], TRUE) or die(mysql_error());
It fixes the problem :)
See http://drupal.org/node/20235 for details.