jjjcr Posted August 23, 2012 Share Posted August 23, 2012 hi guys, i'm stuck need your brilliant ideas. just trying to get my hands wet on php and mysql. had this code below, but i'm not getting anything. there's no error displayed, no successful connection message. but using command prompt, i'm able to connect to mysql but using php code cannot. any ideas why there is no message displayed using this code below, if i run the code it's just a blank page. please help, thanks in advance. <html> <body> <?php // we connect to example.com and port 3307 $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); // we connect to localhost at port 3307 $link = mysql_connect('127.0.0.1', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/267471-cannot-connect-to-mysql/ Share on other sites More sharing options...
jjjcr Posted August 23, 2012 Author Share Posted August 23, 2012 :'( any help please...? :'( Quote Link to comment https://forums.phpfreaks.com/topic/267471-cannot-connect-to-mysql/#findComment-1371768 Share on other sites More sharing options...
PFMaBiSmAd Posted August 23, 2012 Share Posted August 23, 2012 What does the 'view source' of the blank page show? What exact URL are you entering in your browser for that page? Quote Link to comment https://forums.phpfreaks.com/topic/267471-cannot-connect-to-mysql/#findComment-1371774 Share on other sites More sharing options...
Christian F. Posted August 23, 2012 Share Posted August 23, 2012 Also, please use the tags when posting code, as it helps make both your post and the code a lot easier to read. As for the blank page: That sounds like the classic PHP fatal error with error reporting turned off. You should always have full error reporting turned on on your development server, as it'll tell you exactly what fails and why. In a pinch you can check the error logs for the server, but it's a lot easier to just have the error reporting turned on. PS: You'll also want to use the MySQLi library of functions, as the mysql_* () functions are deprecated and will be removed soon. Plus, no need to manually close the connection to the database server, PHP handles that stuff automatically. Quote Link to comment https://forums.phpfreaks.com/topic/267471-cannot-connect-to-mysql/#findComment-1371843 Share on other sites More sharing options...
jjjcr Posted August 28, 2012 Author Share Posted August 28, 2012 thank you guys, for all your replies.. i had installed WAMP it seems to be working now. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/267471-cannot-connect-to-mysql/#findComment-1373125 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.