Nodral Posted July 26, 2011 Share Posted July 26, 2011 Hi I have just set up a hosted site and cannot connect to the MySQL DB. I have set up the correct DB and User but it just keeps failing at the 1st attempt My code is <?php session_start(); $link = mysql_connect('localhost', 'styles', '******'); if (!$link) { echo'1Unable to connect to the database server.'; echo mysql_errno($link) . ": " . mysql_error($link). "\n"; exit(); } if (!mysql_set_charset('utf8', $link)) { echo'2Unable to connect to the database server.'; echo mysql_errno($link) . ": " . mysql_error($link). "\n"; exit(); } if(!mysql_select_db('learning_styles', $link)) { echo'3Unable to connect to the database server.'; echo mysql_errno($link) . ": " . mysql_error($link). "\n"; exit(); } ?> All I get output is 1Unable to connect to the database server.: But no error message. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/242833-no-connection-no-error/ Share on other sites More sharing options...
Nodral Posted July 26, 2011 Author Share Posted July 26, 2011 Sorted, just found in very small print not to use localhost and to use a designated ip address Quote Link to comment https://forums.phpfreaks.com/topic/242833-no-connection-no-error/#findComment-1247231 Share on other sites More sharing options...
the182guy Posted July 26, 2011 Share Posted July 26, 2011 Are your PHP errors hidden? Use error_reporting(E_ALL); ini_set('display_errors', '1'); Also check your hosts control panel for the error log. Your host may be using a pipe for MySQL connections in which case you use '.' as your host, or your host may be using an external server for MySQL. Edit: nevermind, glad you solved it. Quote Link to comment https://forums.phpfreaks.com/topic/242833-no-connection-no-error/#findComment-1247236 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.