phpretard Posted April 1, 2008 Share Posted April 1, 2008 Is there a setting somewhere that could prevent connection to a database from a different server? I am trying to connect to DB1 setup at Server1 from a site hosted at Server2. The code works fine from Server1 to DB1 but not from Server2 to DB1. I hope this question makes sense. Let me know if you need clarification to help I use the exact same code for both. $con = mysql_connect("thehost","Stinks","Pretty"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Stinks", $con); -Anthony Quote Link to comment https://forums.phpfreaks.com/topic/98977-cant-connect/ Share on other sites More sharing options...
uniflare Posted April 1, 2008 Share Posted April 1, 2008 im sure there are numerous thories as to why this wouldnt work, like firewalls etc on server 2. are you using a hostname or an ip-address as the host? some webservers restrict usernames to a specific host, sometimes "localhost" to prevent outside communication. ------- what error does mysql give? cannot connect to server at local port? or mysql username/pass invalid? thanks Quote Link to comment https://forums.phpfreaks.com/topic/98977-cant-connect/#findComment-506470 Share on other sites More sharing options...
phpretard Posted April 1, 2008 Author Share Posted April 1, 2008 here is the error... Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost'(4) in /home/content/t/h/e/html/connect.php on line 2 Could not connect: Can't connect to MySQL server on 'localhost'(4) Quote Link to comment https://forums.phpfreaks.com/topic/98977-cant-connect/#findComment-506484 Share on other sites More sharing options...
uniflare Posted April 1, 2008 Share Posted April 1, 2008 lcoalhost means current machine, you need to use a domain name (hostname) or an ip address of the DB1 server. Quote Link to comment https://forums.phpfreaks.com/topic/98977-cant-connect/#findComment-506496 Share on other sites More sharing options...
phpretard Posted April 1, 2008 Author Share Posted April 1, 2008 I know that...I replaced - h32mysql80.servesecurer.net - with - localhost - just for posting purposes. Quote Link to comment https://forums.phpfreaks.com/topic/98977-cant-connect/#findComment-506506 Share on other sites More sharing options...
trq Posted April 1, 2008 Share Posted April 1, 2008 You need to give your user permissions to connect to DB1 from Server2. eg; GRANT ALL PRIVILEGES ON *.* TO 'user'@'Server2' IDENTIFIED BY 'pass' WITH GRANT OPTION; Quote Link to comment https://forums.phpfreaks.com/topic/98977-cant-connect/#findComment-506508 Share on other sites More sharing options...
phpretard Posted April 1, 2008 Author Share Posted April 1, 2008 In the DB or Code? Quote Link to comment https://forums.phpfreaks.com/topic/98977-cant-connect/#findComment-506511 Share on other sites More sharing options...
uniflare Posted April 1, 2008 Share Posted April 1, 2008 check to see if the default port is different on server1, make sure its the same on server2. also make sure the hostname is correct (obvious i know), try a hostname-lookup. try thorpes idea (use phpmyadmin or similar on server 1 and submit the query) Quote Link to comment https://forums.phpfreaks.com/topic/98977-cant-connect/#findComment-506512 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.