Jump to content

[SOLVED] Bizarre MySQL connection issue when using two different servers


bbbaldie

Recommended Posts

I'm posting this at multiple forums, and promise to post any solution at all of them.

 

I've been a WAMP and LAMP programmmer for nine years, so no noob. But check out this bizzare issue I've never encountered before.

 

First of all, developing on a private intranet. I ran everything on WAMP (one physical server) for years, now have an AD-aware Linux virtual server running CentOS5. My goal is to migrate everything off of the Windows machine. I've already migrated a bunch of stuff over, still connecting to the Windows machine's MySQL. Another goal is to move all MySQL over to Linux as well, and use localhost connection statements to eliminate sending a username and password over the network.

 

Thus, I've created a DB on the Linux side called production. I have a DB on Windows called users.

 

Here are my connection statements:

 

$prodconn=mysql_connect('localhost', 'myuser', 'mypass');

$users = mysql_connect('web4', 'myotheruser', 'myotherpass');

I confirm that both connections are made thusly:

if($prodconn) echo "OK Prodc!";

if($users) echo " Users OK!";

 

and get both echos.

 

However...This bombs:

f($prodconn){

echo "Connected! ";

$sq=mysql_query("SELECT * FROM production.tally")or die('CRAP! '.mysql_error());

echo "Connected!";

}

 

with

 

Connected! CRAP! Table 'production.tally' doesn't exist

 

If I comment out the $users string I get

 

Connected! Connected!

However...

I get other errors from $users being missing, of course. If I change the order of the connection statements:

 

$users = mysql_connect('web4', 'myotheruser', 'myotherpass');

$prodconn=mysql_connect('localhost', 'myuser', 'mypass');

 

I get the same errors (from $users not functioning).

In other words, both connections are successfully made, but only the final connection statement will allow me to run a table query, even with "SELECT table.tally" type statements.

 

Sorry for the length, but I wanted all to know I've already tried a bunch of stuff, and also Googled for a similar issue, and have come up dry both times.

Any ideas?

Link to comment
Share on other sites

From the mysql_query() page in the documentation -

 

resource mysql_query ( string $query [, resource $link_identifier ] )

 

link_identifier

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated.

 

mysql_query uses the last link opened unless you specify the link identifier when you call mysql_query(). When working with more than one link, you should always use the link identifier in the msyql_query() statement.

 

Link to comment
Share on other sites

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.