Jump to content

Recommended Posts

I have the following:

 

function List($db, $zip = false) {

$db->selectDb('database2');

$town = $db->getRow("SELECT * FROM towns_zipcodes, towns WHERE town_zipcodes.zip = '$zip' AND towns_zipcodes.town_id = towns_zipcodes.zip AND towns.id = towns_zipcodes.towns_id AND towns.id = towns.name LIMIT 1");

return $town;

}

 

The page this is for is connected to database1, but I need to query databse2 to get these results.

 

What is the correct way to query another database while connected to database1?

i never try that before. But why you want to connect to 2 DB at once? 1 DB stores many tables which is good enough.

 

to connect DB, we need to establish connection. So if you want 2 DB, you are likely to need to make connection to DB twice. but this is not encouragable. Using one DB and have many tables inside is good enough.

 

tell me the reason you want 2 DB. Thanks.

I need to connect to two because one has a lot of tables, and so does the second. And they are used for different things.

 

To connect to the first I use the standard mysql_connect. However, while under that connection, I need to open a new connection to retrieve data to display on the same page. I tried using mysql_select_db but it did not work.

 

Any suggestions?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.