Search different databases

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
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Search different databases

Post by Maluendaster »

hey, i want to do a search from different databases (it's the same for all of them), is for an automotive site.. Is there anyway I can merge in a search and search like 100 databases and display the resulst???
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

not in one search as each db will have it's own username and password which is required in order to make the connection to be able to query it.
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post by Maluendaster »

phpScott wrote:not in one search as each db will have it's own username and password which is required in order to make the connection to be able to query it.
all the databases have the same user/password...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

nonetheless, you are going to have to loop through each database, and select it.

Code: Select all

$db = array('127.0.0.1' => 'some_database',
            '127.0.0.2' => 'a_database') ;

foreach ($db as $host => $new_db)
{
     mysql_connect($host,$user,$pass) or die(mysql_error());
     mysql_select_db($new_db);

     //run search here
}
I have never heard of any "easy" way to access multiple databases concurantly.
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Is it > 1 database on the same MySQL server? Or numerous database engines? If it is just the same server, using mysql_select_db in a loop. Otherwise, ADOdb might come in handy.
Post Reply