Jump to content

Is there a way to connect to one mysql db while connected to another one?


tibberous
 Share

Recommended Posts

I am using a 3rd party lookup service. Basically, they have you connect to their mysql database, select their db and do a query.

 

I tried:

 

$newconn = mysql_connect()
mysql_select_db('db', $newconn);
mysql_query("...", $newconn);
mysql_close($newconn);

 

But if I try to do mysql_queries without sending $newconn I still get errors. For right now, I'm just closing my first connection and reconnecting, but it seems like there should be a way to query a second database without messing up the connect to the first one.

Link to comment
Share on other sites

I am using a 3rd party lookup service. Basically, they have you connect to their mysql database, select their db and do a query.

 

I tried:

 

$newconn = mysql_connect()
mysql_select_db('db', $newconn);
mysql_query("...", $newconn);
mysql_close($newconn);

 

But if I try to do mysql_queries without sending $newconn I still get errors. For right now, I'm just closing my first connection and reconnecting, but it seems like there should be a way to query a second database without messing up the connect to the first one.

 

There's a boolean you can set in mysql_connect that will force it to create a new, parallel connection to a db: mysql_connect  However, I think it only applies if you're trying to attempt multiple connections to the same db.  If the db's are actually different, then the db handle you create during mysql_connect should be enough.

 

Can you show more code in how you're creating and using these connections?

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.