Jump to content

Connection Function


stig1

Recommended Posts

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);
}

};

Link to comment
https://forums.phpfreaks.com/topic/167688-connection-function/
Share on other sites

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());

Link to comment
https://forums.phpfreaks.com/topic/167688-connection-function/#findComment-884430
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.