dprichard Posted June 13, 2007 Share Posted June 13, 2007 I am setting up a connection to a mysql database. I am trying to display a custom error message if something goes wrong with the connection instead of say something like this. PHP Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ttracker'@'localhost' (using password: YES) in C:\DATA\ttracker.dsolutionsgroup.com\htdocs\Connections\time_tracker_connection.php on line 2 PHP Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in C:\DATA\ttracker.dsolutionsgroup.com\htdocs\Connections\time_tracker_connection.php on line 2 I purposely put in the wrong password here to see what came up. This is my code and I was trying to figure out how to say something more normal sounding than displaying the typical error messages if there is a problem with the connection. <?php mysql_connect("localhost", "username", "password") or die(mysql_error("Could not connect to the database. Please contact a site administrator for assistance!")); echo "Connected to the database"; ?> Any assistance would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/55407-solved-displaying-custom-error-on-connection-failure-to-database/ Share on other sites More sharing options...
dprichard Posted June 13, 2007 Author Share Posted June 13, 2007 Okay, I changed it to this: <?php mysql_connect("localhost", "username", "password") or die("Could not connect to the database. Please contact a site administrator for assistance!"); echo "Connected to the database"; ?> And now I am getting this: Could not connect to the database. Please contact a site administrator for assistance!PHP Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ttracker'@'localhost' (using password: YES) in C:\DATA\ttracker.dsolutionsgroup.com\htdocs\Connections\time_tracker_connection.php on line 2 Is there a way to suppress the PHP Warning part of the connection error? Link to comment https://forums.phpfreaks.com/topic/55407-solved-displaying-custom-error-on-connection-failure-to-database/#findComment-273828 Share on other sites More sharing options...
Illusion Posted June 13, 2007 Share Posted June 13, 2007 error_reporting(E_ALL ^ E_WARNING); add this at the top of the page , it won't display any warnings.Anyway you don't need the warning messages as you are going for customized messages. Link to comment https://forums.phpfreaks.com/topic/55407-solved-displaying-custom-error-on-connection-failure-to-database/#findComment-273850 Share on other sites More sharing options...
dprichard Posted June 13, 2007 Author Share Posted June 13, 2007 Awesome, thank you!!!!! Link to comment https://forums.phpfreaks.com/topic/55407-solved-displaying-custom-error-on-connection-failure-to-database/#findComment-273856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.