tanvirtonu Posted August 19, 2011 Share Posted August 19, 2011 Hello I m new to php. I have uploaded a simple php script in my web root - http://www.mydomain.com which will connect to my DB. But strangely I CANT connect to my DB if I put the hostname as my real hostname - mydomain.com . But if I use - localhost , it works. How come its working as- localhost when I am not on localhost. <?php echo "HELLO WORLD"; $connect = mysql_connect("localhost","username","mypassword") or die ("couldn't connect db"); // it works //$connect = mysql_connect("www.mydomain.com","username","mypassword") or die ("couldn't connect db"); // it DOESN'T work ?> Quote Link to comment https://forums.phpfreaks.com/topic/245183-php-database-connection-problem-in-webserver/ Share on other sites More sharing options...
MasterACE14 Posted August 19, 2011 Share Posted August 19, 2011 because that is what the hostname is set to for your webserver, this is common practice. Quote Link to comment https://forums.phpfreaks.com/topic/245183-php-database-connection-problem-in-webserver/#findComment-1259345 Share on other sites More sharing options...
titan21 Posted August 19, 2011 Share Posted August 19, 2011 Best way to think about it is that the script is running on the server (not the client) so localhost is correct! Quote Link to comment https://forums.phpfreaks.com/topic/245183-php-database-connection-problem-in-webserver/#findComment-1259364 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.