RE: [PHP] Connection to Two databases simultaneously

2005-04-04 Thread Kim Madsen
> -Original Message-
> From: HarryG [mailto:[EMAIL PROTECTED]
> Sent: Saturday, April 02, 2005 6:29 AM

> I am connecting to two database in my index.php.

If the 2 databases are on the same mysql server and the MySQL user has access 
to both databases, You can easily use join:

Select name FROM db1.members, db2.addresses WHERE db1.members.id = 
db2.addresses.member_id

It´s been a while(years!) since I´ve used this, so I´m sorry if the syntax 
ain´t correct.

--
Med venlig hilsen / best regards
ComX Networks A/S
Kim Madsen
Systemudvikler/systemdeveloper

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



Re: [PHP] Connection to Two databases simultaneously

2005-04-02 Thread Dan Rossi
both db's on the same host ?
I would try select * from second_db2.theothertable :)
On 02/04/2005, at 6:53 PM, Jochem Maas wrote:
HarryG wrote:
Hi,
I am connecting to two database in my index.php.
Here is how:
@ $db = mysql_connect("localhost", USERLOGIN, USERDBPASS);
 if (!$db)
 {  print "Error: Could not connect to database. Please try again 
later.";  exit; }
mysql_select_db(DATABASE);
@ $userdb = mysql_connect("localhost", USERLOGIN, USERDBPASS);
 if (!$userdb)
 {  print "Error: Could not connect to database. Please try again 
later.";  exit; }
mysql_select_db(USERDB);
$getaccount = "SELECT * FROM account WHERE visible=1";  //Account 
table is present in USERDB.
$result = mysql_query($getaccount);
$get = "SELECT * FROM useraccount";  //UserAccount table is present 
in DATABASE.
$result = mysql_query($get);
There is no problem with the connection. but I need to query tables 
in both databases. I know you need to use link identifiers, but have 
had no luck in getting it to work. Appreciate your help.
er, you are not actually using the link identifiers try like this:
@ $db = mysql_connect("localhost", USERLOGIN, USERDBPASS);
if (!$db) {
	print "Error: Could not connect to database. Please try again 
later.";  exit; }
	mysql_select_db(DATABASE, $db);
}

@ $userdb = mysql_connect("localhost", USERLOGIN, USERDBPASS);
if (!$userdb) {
	print "Error: Could not connect to database. Please try again 
later.";  exit; }
	mysql_select_db(USERDB, $userdb);
}

$getaccount = "SELECT * FROM account WHERE visible=1";  //Account 
table is present in USERDB.
$result = mysql_query($getaccount, $userdb);

$get = "SELECT * FROM useraccount";  //UserAccount table is present in 
DATABASE.
$result = mysql_query($get, $db);

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


Re: [PHP] Connection to Two databases simultaneously

2005-04-02 Thread Jochem Maas
HarryG wrote:
Hi,
I am connecting to two database in my index.php.
Here is how:
@ $db = mysql_connect("localhost", USERLOGIN, USERDBPASS);
 if (!$db)
 {  print "Error: Could not connect to database. Please try again later.";  
exit; }
mysql_select_db(DATABASE);
@ $userdb = mysql_connect("localhost", USERLOGIN, USERDBPASS);
 if (!$userdb)
 {  print "Error: Could not connect to database. Please try again later.";  
exit; }
mysql_select_db(USERDB);
$getaccount = "SELECT * FROM account WHERE visible=1";  //Account table is 
present in USERDB.
$result = mysql_query($getaccount);
$get = "SELECT * FROM useraccount";  //UserAccount table is present in DATABASE.
$result = mysql_query($get);
There is no problem with the connection. but I need to query tables in both databases. I know you need to use link identifiers, 
but have had no luck in getting it to work. Appreciate your help.
er, you are not actually using the link identifiers try like this:
@ $db = mysql_connect("localhost", USERLOGIN, USERDBPASS);
if (!$db) {
print "Error: Could not connect to database. Please try again later.";  
exit; }
mysql_select_db(DATABASE, $db);
}
@ $userdb = mysql_connect("localhost", USERLOGIN, USERDBPASS);
if (!$userdb) {
print "Error: Could not connect to database. Please try again later.";  
exit; }
mysql_select_db(USERDB, $userdb);
}
$getaccount = "SELECT * FROM account WHERE visible=1";  //Account table is 
present in USERDB.
$result = mysql_query($getaccount, $userdb);
$get = "SELECT * FROM useraccount";  //UserAccount table is present in DATABASE.
$result = mysql_query($get, $db);
Thanks.
HarryG
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php