Hi,

i added a php page to my new beta2 frontpage.
This php page accesses the database, but only for a database/tables not related to drupal.
- I use a db-link for the connect
- I use a db-link for the select_db
- I free my result after the query
- i close the connection for my dblink afterwards

but drupal is still giving me lots or warnings like:
# user warning: Table 'AO.book' doesn't exist query: SELECT * FROM book WHERE vid = 1 in /var/www/html/includes/database.mysql.inc on line 108.
# user warning: Table 'AO.node_counter' doesn't exist query: SELECT totalcount, daycount, timestamp FROM node_counter WHERE nid = 1 in /var/www/html/includes/database.mysql.inc on line 108.
# user warning: Table 'AO.term_node' doesn't exist query: SELECT t.* FROM term_node r INNER JOIN term_data t ON r.tid = t.tid INNER JOIN vocabulary v ON t.vid = v.vid WHERE r.nid = 1 ORDER BY v.weight, t.weight, t.name in /var/www/html/includes/database.mysql.inc on line 108.

(note : the non-drupal db i'm accessing is called 'AO')

If i try to load this page in the frontpage, it destroys the drupal layout
(probably because he cannot complete his db operations, since he's trying to access the wrong database.)

Ban

Comments

ban-1’s picture

I have been able to solve this error for my case, but my solution is not very clean:

added the follwing line to includes/database.mysql.inc :
if (variable_get('dev_query', 0)) {
list($usec, $sec) = explode(' ', microtime());
$timer = (float)$usec + (float)$sec;
}
mysql_select_db('drupal',$active_db); <<<<<<<<<<<<<<
$result = mysql_query($query, $active_db);

forcing drupal to use the drupal database for its queries.

I'm a total newbie to drupal devel, so i'm hoping that there is someone who could turn this into a nice patch ?

Thanks,
Ban

jose reyero’s picture

Component: base system » database system
Category: bug » support

I'd say this is not a drupal bug because it is related to some 'extra' code you have in a page so it should be a support request. Also changed component to database system.

Please, lets keep the bug queue clean.

And if youwant any help on your custom code, maybe better post that code....

Cheers

ban-1’s picture

Assigned: Unassigned » ban-1
Status: Active » Needs review

i'm sorry, but i have to disagree with you there.
it's not my "extra" code that doesn't work, it actually works flawlessly.

The issue is that if i use any PHP code that accesses a database other then drupals,
drupal 'forgets' the name of its database, just follows the open persistent link and ends up accessing a database other then its own.
eg, drupal doesn't display anything.

I didn't provide my code, since it's just a select from an external db and display the resulting string.

i'm very sorry this clutters up the bug queue, that's not my intention.
but i really think this should be considered as a bug for drupal.

It's solved by changing the mysql_select_db call in includes/database.mysql.inc to :

mysql_select_db('drupal',$active_db);

so i will change status to patch to be reviewed
please let me know if this can become a bug or has to remain as a support request.

Thanks,
Ban

moshe weitzman’s picture

Category: support » bug
Priority: Normal » Minor
Status: Needs review » Active
Jaza’s picture

Version: 4.7.0-beta2 » 4.7.0

Probably still an issue in 4.7.0 - if anyone can confirm this problem, please post updates here.

nevets’s picture

I think what you want to do is read http://drupal.org/node/18429 which shows how to connect to multiple databases within Drupal.

killes@www.drop.org’s picture

Category: bug » support
Status: Active » Closed (fixed)

look at the docs for db_set_active().