jparker Posted April 24, 2006 Share Posted April 24, 2006 Hello I'm trying to get php to work with mysql. If I log onto mysql with my credentials I can look at the database and so some commands.If I attempt to do the same in php via a script : -<?php$link = mysql_connect('localhost', 'james', 'password');if (!$link) {print('Could not connect: ' . mysql_error());exit;}echo 'Connected successfully';mysql_close($link);?>I don't get to see the success message but neither do I get the error message. Could someone please spread some light on this as I have a long way to go on my php/mysql journey and this is depressingly early roadblock.James Quote Link to comment https://forums.phpfreaks.com/topic/8257-cant-connect-to-a-database-through-php/ Share on other sites More sharing options...
kenrbnsn Posted April 24, 2006 Share Posted April 24, 2006 Use the "or die" clause instead of the "if" statement:[code]<?php$link = mysql_connect('localhost', 'james', 'password') or die('Could nit connect: ' . mysql_error());echo 'Connected successfully';mysql_close($link);?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/8257-cant-connect-to-a-database-through-php/#findComment-30121 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.