xwishmasterx Posted August 9, 2011 Share Posted August 9, 2011 Hello I have followed a few guides / ideas but I simple can't get this too work properly. I can connect to the remote server and do quries and all, but getting anything from my own server (where the script is being runned) is just not happening. Does anyone have a link or example I can look at? Quote Link to comment https://forums.phpfreaks.com/topic/244324-connecting-to-two-mysql-databases-one-remote/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 9, 2011 Share Posted August 9, 2011 If you want help with what your code is doing, you will need to post your code, along with any errors or symptoms you saw that lead to you believe your script is not working. If you have two active database connections in one script, it is likely that the problem is that you need to specify the correct connection when you execute a query against the database where your script is running at. Quote Link to comment https://forums.phpfreaks.com/topic/244324-connecting-to-two-mysql-databases-one-remote/#findComment-1254914 Share on other sites More sharing options...
xwishmasterx Posted August 9, 2011 Author Share Posted August 9, 2011 What I have done is this, following an example I found.. <?php $server = "xxxxxxxxxxxxxxx"; $dbname = "lxxxxxxxxxxxxxxx"; $user = "xxxxxxxxxx"; //Allowed for the ip $password = "xxxxxxxxxxxx"; $link = mysql_connect($server,$user,$password) or die(mysql_error()); mysql_select_db($dbname); ?> <?php $hostname = "localhost"; $username = "xxxxxxxxxx"; $password = "xxxxxxxxxxxxxxxx"; $dbname2 = "xxxxxxxxxx"; $dbh1 = mysql_connect($hostname, $username, $password) or die(mysql_error()); mysql_select_db($dbname2); ?> I have tried these to queries: <?php $home_members = mysql_query ("SELECT DISTINCT (credit_members_id) as homememberid FROM vtp_tracking WHERE action_date>date_sub(NOW(),interval 5 minute) AND credit_members_id=57983", $link) or die(mysql_error()); $rs_home_members = mysql_fetch_array( $home_members ); $home_member = $rs_home_members['homememberid']; echo " $home_member "; ?> <?php $away_members = mysql_query ("SELECT name FROM vtp_members WHERE id='58106' ", $dbh1) or die(mysql_error()); $rs_away_members = mysql_fetch_array( $away_members ); $away_member = $rs_away_members['name']; echo " $away_member "; ?> I can get a result from the first query, but none from the other. I am certain that it is the connection that is the problem or the wrong database. Quote Link to comment https://forums.phpfreaks.com/topic/244324-connecting-to-two-mysql-databases-one-remote/#findComment-1254961 Share on other sites More sharing options...
fenway Posted August 9, 2011 Share Posted August 9, 2011 Are you sure your connections work? Quote Link to comment https://forums.phpfreaks.com/topic/244324-connecting-to-two-mysql-databases-one-remote/#findComment-1255000 Share on other sites More sharing options...
PFMaBiSmAd Posted August 9, 2011 Share Posted August 9, 2011 Again, you didn't state what symptom or error you are getting that leads you to believe the second one is not working. BTW - mysql_error() would need the correct link resource so that it would output the last error that occurred on the specific connection. You also need to use the correct link resource in the mysql_select_db statements. Quote Link to comment https://forums.phpfreaks.com/topic/244324-connecting-to-two-mysql-databases-one-remote/#findComment-1255046 Share on other sites More sharing options...
xwishmasterx Posted August 10, 2011 Author Share Posted August 10, 2011 I have checked the connections and both are fine. It seems the problem running this part, when the other connection is there: <?php $away_members = mysql_query ("SELECT name FROM vtp_members WHERE id='58106' ", $dbh1) or die(mysql_error()); $rs_away_members = mysql_fetch_array( $away_members ); $away_member = $rs_away_members['name']; echo " $away_member "; ?> If I remove the connection to the remote server the above part works fine. Quote Link to comment https://forums.phpfreaks.com/topic/244324-connecting-to-two-mysql-databases-one-remote/#findComment-1255164 Share on other sites More sharing options...
fenway Posted August 10, 2011 Share Posted August 10, 2011 Then something is stepping on something else. Quote Link to comment https://forums.phpfreaks.com/topic/244324-connecting-to-two-mysql-databases-one-remote/#findComment-1255252 Share on other sites More sharing options...
xwishmasterx Posted August 10, 2011 Author Share Posted August 10, 2011 you think? So there is nothing with the coding that looks wrong? Quote Link to comment https://forums.phpfreaks.com/topic/244324-connecting-to-two-mysql-databases-one-remote/#findComment-1255297 Share on other sites More sharing options...
PFMaBiSmAd Posted August 10, 2011 Share Posted August 10, 2011 There's at least two different things wrong with the code, that someone already posted - BTW - mysql_error() would need the correct link resource so that it would output the last error that occurred on the specific connection. You also need to use the correct link resource in the mysql_select_db statements. Quote Link to comment https://forums.phpfreaks.com/topic/244324-connecting-to-two-mysql-databases-one-remote/#findComment-1255300 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.