RE: [PHP-DB] accessing two databases within one script

2004-10-05 Thread Oscar Rylin
Of course you can

$whatever_db_linkid = mysql_connect($connectiondetails_for_whatever_db);
if(is_resource($whatever_db_linkid)) { mysql_select_db('whatever_db',
$whatever_db_linkid); }

$someother_db_linkid = mysql_connect($connectiondetails_for_someother_db);
if(is_resource($someother_db_linkid)) { mysql_select_db('someother_db',
$someother_db_linkid); }

// work your magic..



mysql_close($whatever_db_linkid);
mysql_close($someother_db_linkid);

-Original Message-
From: Gary Rachel [mailto:[EMAIL PROTECTED] 
Sent: den 5 oktober 2004 04:31
To: [EMAIL PROTECTED]
Subject: [PHP-DB] accessing two databases within one script

I have a page where I need to access two different databases in mysql.  
After accessing the first database I used  mysql_close($connection);
and then code to access the other database.  The first database access 
works fine, the second gives me the following error message:

*Warning*: mysql_query(): Can't connect to local MySQL server through 
socket '/tmp/mysql.sock'

I've tried not using the mysql_close statement.  But that option doesn't 
select the new database, it seems to stay connected to the previous one, 
despite my specifying a new database to access.  Can I not access two 
databases within the same script?

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] accessing two databases within one script

2004-10-05 Thread Graham Cossey

I have several databases running on the same MySQL server and one
application needs to run queries over two DBs at the same time. All I do is
specify one connect (to the primary DB) and then specify the secondary DB
within my queries. This seems to work fine, but not sure if it's discouraged
for any reason.

DB1 contains table product.
DB2 contains table customer.

$link = mysql_connect(DB1);
$sql = SELECT c.custname, p.prodname FROM DB2.customer as c JOIN product as
p ON c.prodid=p.prodid

(This is NOT real code :) )

HTH

Graham
-Original Message-
From: Gary Rachel [mailto:[EMAIL PROTECTED]
Sent: 05 October 2004 03:31
To: [EMAIL PROTECTED]
Subject: [PHP-DB] accessing two databases within one script


I have a page where I need to access two different databases in mysql.
After accessing the first database I used  mysql_close($connection);
and then code to access the other database.  The first database access
works fine, the second gives me the following error message:

*Warning*: mysql_query(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock'

I've tried not using the mysql_close statement.  But that option doesn't
select the new database, it seems to stay connected to the previous one,
despite my specifying a new database to access.  Can I not access two
databases within the same script?

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] accessing two databases within one script

2004-10-05 Thread Andrew Kreps
On Mon, 04 Oct 2004 22:31:15 -0400, Gary Rachel [EMAIL PROTECTED] wrote:
 I've tried not using the mysql_close statement.  But that option doesn't
 select the new database, it seems to stay connected to the previous one,
 despite my specifying a new database to access.  Can I not access two
 databases within the same script?

I'm assuming that you're using localhost in both mysql_connect
statements.  You may want to try using the new_link option of the
mysql_connect function.  PHP might be trying to use your old (and
disconnected) link when you make your second connect call.  Have a
look at the function call docs for details on using that option.

http://us4.php.net/mysql_connect

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php