stig1 Posted July 27, 2009 Share Posted July 27, 2009 I currently use this as my connection function to mysql, however, if the database connection fails there no way of it telling me, instead of using the or die statments i would rather it email me, with the mysql related error no and error msg. Is this possible? class DB_MySQL { var $connection; function DB_MySQL(){ $this->connection = mysql_connect(MYSQL_SERVER, MYSQL_USR, MYSQL_PASS); mysql_select_db(MYSQL_DB, $this->connection); } }; Quote Link to comment https://forums.phpfreaks.com/topic/167688-connection-function/ Share on other sites More sharing options...
ldougherty Posted July 28, 2009 Share Posted July 28, 2009 There is no way in mySQL to be notified via email of any SQL errors. You could however write your own script which checks an error log for any new information after x amount of time via cron and emails you the results if found. Quote Link to comment https://forums.phpfreaks.com/topic/167688-connection-function/#findComment-884426 Share on other sites More sharing options...
.josh Posted July 28, 2009 Share Posted July 28, 2009 function email_db_error() { $to = "[email protected]"; $subject = "db error"; $content = "The following error occured on: " . date("Y.m.d H:i:s") . "\n\n"; $content.= mysql_error(); mail($to,$subject,$content); } // example $conn = mysql_query('blah') or trigger_error(email_db_error()); Quote Link to comment https://forums.phpfreaks.com/topic/167688-connection-function/#findComment-884430 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.