PRodgers4284 Posted April 18, 2008 Share Posted April 18, 2008 I am trying to test a database connection to a mySql database, i want to output a message if the connection to the database is successfully connected, if not output an error. Anyone help with this? The connection im using is: <?php /** * Connect to the mysql database. */ $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db('localdatabase', $conn) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/101684-testing-database-connection/ Share on other sites More sharing options...
Rowno Posted April 18, 2008 Share Posted April 18, 2008 <?php $conn = mysql_connect("localhost", "root", ""); if ($conn) { echo "Successfully connected.<br />"; } else { die(mysql_error()) } if (mysql_select_db('localdatabase', $conn)) { echo "Successfully selected a database<br />"; } else { die(mysql_error()); } ?> Try that, it should echo a message on success and display the error message on failure. Link to comment https://forums.phpfreaks.com/topic/101684-testing-database-connection/#findComment-520221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.