MDL-47584 database SQL: add debug info on connection error notices
This commit is contained in:
committed by
Damyon Wiese
parent
917d5e1caa
commit
aa4318a823
@@ -441,13 +441,10 @@ class mysqli_native_moodle_database extends moodle_database {
|
||||
if ($dbhost and !empty($this->dboptions['dbpersist'])) {
|
||||
$dbhost = "p:$dbhost";
|
||||
}
|
||||
ob_start();
|
||||
$this->mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbsocket);
|
||||
$dberr = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$errorno = @$this->mysqli->connect_errno;
|
||||
$this->mysqli = @new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbsocket);
|
||||
|
||||
if ($errorno !== 0) {
|
||||
if ($this->mysqli->connect_errno !== 0) {
|
||||
$dberr = $this->mysqli->connect_error;
|
||||
$this->mysqli = null;
|
||||
throw new dml_connection_exception($dberr);
|
||||
}
|
||||
|
||||
+7
-2
@@ -344,6 +344,11 @@ function setup_DB() {
|
||||
$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, $CFG->dboptions);
|
||||
} catch (moodle_exception $e) {
|
||||
if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) {
|
||||
$body = "Connection error: ".$CFG->wwwroot.
|
||||
"\n\nInfo:".
|
||||
"\n\tError code: ".$e->errorcode.
|
||||
"\n\tDebug info: ".$e->debuginfo.
|
||||
"\n\tServer: ".$_SERVER['SERVER_NAME']." (".$_SERVER['SERVER_ADDR'].")";
|
||||
if (file_exists($CFG->dataroot.'/emailcount')){
|
||||
$fp = @fopen($CFG->dataroot.'/emailcount', 'r');
|
||||
$content = @fread($fp, 24);
|
||||
@@ -352,7 +357,7 @@ function setup_DB() {
|
||||
//email directly rather than using messaging
|
||||
@mail($CFG->emailconnectionerrorsto,
|
||||
'WARNING: Database connection error: '.$CFG->wwwroot,
|
||||
'Connection error: '.$CFG->wwwroot);
|
||||
$body);
|
||||
$fp = @fopen($CFG->dataroot.'/emailcount', 'w');
|
||||
@fwrite($fp, time());
|
||||
}
|
||||
@@ -360,7 +365,7 @@ function setup_DB() {
|
||||
//email directly rather than using messaging
|
||||
@mail($CFG->emailconnectionerrorsto,
|
||||
'WARNING: Database connection error: '.$CFG->wwwroot,
|
||||
'Connection error: '.$CFG->wwwroot);
|
||||
$body);
|
||||
$fp = @fopen($CFG->dataroot.'/emailcount', 'w');
|
||||
@fwrite($fp, time());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user