GrayFox12 Posted September 30, 2009 Share Posted September 30, 2009 Hi guys, Im just trying to connect to my mysql running on the same machine but am having difficulties. Heres what I got: mysql_connect("localhost:3306", "username", "password") or die("Unable to connect to server ".mysql_error()); $h = "localhost:3306"; $u = "username"; $p = "password"; $connection=mysql_connect($h,$u,$p); mysql_select_db("database") or die(mysql_error()); echo "here"; My problem is that this isnt working and I am left with a blank page with no error message so I dont even know what the problem is. Please help me cheers GrayFox Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/ Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 Any specific reason your specifying a port on the hostname? When you say blank page do you mean you don't even have the word "here" appear? How come you are trying to connect twice in your code? Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/#findComment-927632 Share on other sites More sharing options...
GrayFox12 Posted September 30, 2009 Author Share Posted September 30, 2009 Thats the port where mysql instance is running on. My xampp which is my webserver is on port 80. Yea just completly blank word "here" does not show up. When I remove the connection code "here" does come up so I know it is running php script. Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/#findComment-927636 Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 What do you get if you have just this on your page? <?php $h = "localhost"; $u = "username"; $p = "password"; $connection = mysql_connect($h,$u,$p) or die(mysql_error()); mysql_select_db("database", $connection) or die(mysql_error()); echo "here"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/#findComment-927642 Share on other sites More sharing options...
GrayFox12 Posted September 30, 2009 Author Share Posted September 30, 2009 Same thing just nothing. Shouldnt I be getting a error message coming up? Thats my real problem Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/#findComment-927644 Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 How about if you have this... <?php $h = "localhost"; $u = "username"; $p = "password"; $connection = mysql_connect($h,$u,$p) or die("Connection"); mysql_select_db("database", $connection) or die("Database"); echo "here"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/#findComment-927647 Share on other sites More sharing options...
PFMaBiSmAd Posted September 30, 2009 Share Posted September 30, 2009 You are likely getting a fatal runtime error because the mysql extension is not enabled. Before you go any further trying to use php on your development system, please permanently set error_reporting to E_ALL and display_errors to ON in your php.ini so that php will help you by displaying all the errors it detects. Stop and start your web server to get any change made to php.ini to take effect and use a phpinfo() statement to confirm that the settings were actually changed in case the php.ini that you are changing is not the one that php is using. You will save a ton of time leaning php, developing php code, and debugging php code by having those two settings as indicated. Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/#findComment-927662 Share on other sites More sharing options...
GrayFox12 Posted October 1, 2009 Author Share Posted October 1, 2009 Ok I go into my php.ini file and it already says display_errors = on and error_reporting = E_ALL & ~E_NOTICE. I stop and Restart xampp. When I look at phpinfo it has display_errors = off. I begginning to think its looking for the wrong php.ini file. The file i looked at is in c:/Xampp/php is that correct? Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/#findComment-928105 Share on other sites More sharing options...
PFMaBiSmAd Posted October 1, 2009 Share Posted October 1, 2009 The Loaded Configuration File line in the phpinfo() output is the php.ini that php is using. Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/#findComment-928109 Share on other sites More sharing options...
GrayFox12 Posted October 1, 2009 Author Share Posted October 1, 2009 Ok thankyou everybody for your help found the right php file and changed display_errors to on. Never thought ild be so happy to see an error message come up. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/#findComment-928111 Share on other sites More sharing options...
PFMaBiSmAd Posted October 1, 2009 Share Posted October 1, 2009 E_ALL & ~E_NOTICE The above setting disables NOTICE messages. You should not disable NOTICE messages when you are developing and debugging php code as there will be a number of typeo's you will make and other novice errors that the NOTICE message will help you find and fix. Quote Link to comment https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/#findComment-928128 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.