bbbaldie Posted August 7, 2009 Share Posted August 7, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/169237-solved-bizarre-mysql-connection-issue-when-using-two-different-servers/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 7, 2009 Share Posted August 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/169237-solved-bizarre-mysql-connection-issue-when-using-two-different-servers/#findComment-893003 Share on other sites More sharing options...
bbbaldie Posted August 7, 2009 Author Share Posted August 7, 2009 :D THAT'S IT!!!!! Adding both database name and link identifier to all mysql_query() statements makes it all work!!! THANK YOU!!! Quote Link to comment https://forums.phpfreaks.com/topic/169237-solved-bizarre-mysql-connection-issue-when-using-two-different-servers/#findComment-893020 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.