You are here: Re: [PHP] Connection to Two databases simultaneously « PHP « IT news, forums, messages
Re: [PHP] Connection to Two databases simultaneously

Posted by Jochem Maas on 10/21/08 11:12

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
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация