I am trying to establish a connection to a database in another server in order to retrieve some information stored there (from another app, not another Drupal installation).

I put this code to connect in a php node:


//	MySQL server connect
$_SWdb=@mysql_connect("$_SWdbhost","$_SWdbuser","$_SWdbpasswd");

//	MySQL database name
$_SWdb_name="dbname";
$_SWdbname = $_SWdb_name;

$_SWdb_select = @mysql_select_db($_SWdb_name,$_SWdb);

But when viewing the node, it shows this error:

Fatal error: No Database Selected query: INSERT INTO watchdog (uid, type, message, link, location, hostname, timestamp) VALUES (1, 'error', 'user error: No Database Selected query: SELECT t.* FROM term_data t, term_node r WHERE r.tid = t.tid AND r.nid = 15 ORDER BY weight, name in D:\\www\\iwanna\\includes\\database.mysql.inc on line 90.', '', '/conciertos', '127.0.0.1', 1070810236) in D:\www\iwanna\includes\database.mysql.inc on line 90

Fatal error: No Database Selected query: UPDATE sessions SET uid = 1, hostname = '127.0.0.1', session = 'referer|s:24:\"http://iwanna/conciertos\";comment_referer|s:12:\"node/view/15\";node_overview_filter|i:0;', timestamp = 1070810236 WHERE sid = '48f6407b76220a846c93c8b684c14d80' in D:\www\iwanna\includes\database.mysql.inc on line 90

Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0

The problem seen that drupal confuses the database connections and asumes the one I'm trying to create is the one of it's own.

Drupal version 4.3.1 on Apache 2, MySQL 4 and W2K.

Any hint?

Thanks,

álvaro

--

http://interactors.coop

http://furilo.com

Comments

alvaroortiz’s picture

The error which posted before shows if you add

mysql_close($_SWdb);

at the end of the php node, in order to close the external connection I have intended to open.

The error which shows if you do not put the close connection, is this:

Fatal error: Table 'dbname.watchdog' doesn't exist query: INSERT INTO watchdog (uid, type, message, link, location, hostname, timestamp) VALUES (1, 'error', 'user error: Table \'dbname.term_data\' doesn\'t exist query: SELECT t.* FROM term_data t, term_node r WHERE r.tid = t.tid AND r.nid = 15 ORDER BY weight, name in D:\\www\\iwanna\\includes\\database.mysql.inc on line 90.', '', '/conciertos', '127.0.0.1', 1070816584) in D:\www\iwanna\includes\database.mysql.inc on line 90

Fatal error: Table 'dbname.sessions' doesn't exist query: UPDATE sessions SET uid = 1, hostname = '127.0.0.1', session = '', timestamp = 1070816584 WHERE sid = '406807241b409b057a25a46159bccac1' in D:\www\iwanna\includes\database.mysql.inc on line 90

Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0