Possible to select info from DIFFERENT database?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Possible to select info from DIFFERENT database?

Post by thefreebielife »

Is it possible to use this code to select info from DEF if my config file is set to database ABC?

Code: Select all

$data = mysql_query("SELECT * FROM users WHERE uId='$info'")
Would i have to edit the config file?

Thanks.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

mysql_select_db();
||

Code: Select all

$data = mysql_query("SELECT * FROM db2.users WHERE uId='$info'"
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post by xpgeek »

Yes it is possible you can use full path to field name as:

databasename.tablename.fieldname

and You query would be as:

Code: Select all

$data = mysql_query("SELECT * FROM defdb.users u WHERE u.uId='$info'")
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

Assuming that the database is on the same server.
Bon Bon
Forum Commoner
Posts: 66
Joined: Sat Mar 13, 2004 10:21 pm
Location: UK

Post by Bon Bon »

...And you have the correct access rights for that database.

If not you will have to make 2 different database connections and do 2 differnet database queries and use something like array_multisort to combine them both and sort them how you want them.
Post Reply