markpirvine Posted January 7, 2011 Share Posted January 7, 2011 Hi, I have a problem trying to connect to a my_sql database. I'm very new to PHP, so this is probably a very simple problem. At the top of my index.php I have the following code: try { echo 'here 1'; $dbmysql_connect('localhost', 'root', 'password') or die(mysql_error()); echo 'here 2'; if(!$db) { echo 'here 3'; } $db_selected=mysql_select_db("alphaes", $db); echo 'here 4'; if (!$db_selected) { die ('Can\'t use foo : ' . mysql_error()); } echo 'here 5'; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } The problem is that the only output from the page is 'here 1'. If I comment out all the database code the page loads ok. There's something wrong with the connect code, however I don't see the mysql_error or exception. Do these get logged to a file somewhere? Can anyone see a problem with the code? The username and password are correct. Any help is much appreciated, Mark Link to comment https://forums.phpfreaks.com/topic/223666-php-my_sql-connection-problem/ Share on other sites More sharing options...
dragon_sa Posted January 7, 2011 Share Posted January 7, 2011 i think this is the issue $dbmysql_connect('localhost', 'root', 'password') or die(mysql_error()); should be $db=mysql_connect('localhost', 'root', 'password') or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/223666-php-my_sql-connection-problem/#findComment-1156163 Share on other sites More sharing options...
markpirvine Posted January 10, 2011 Author Share Posted January 10, 2011 Hi, Thanks for your reply, that was a typo in my post. The line is $db = mysql_connect... Mark Link to comment https://forums.phpfreaks.com/topic/223666-php-my_sql-connection-problem/#findComment-1157308 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.