Skip to content

Commit 0e381b3

Browse files
committed
Improved mysql error logging.
1 parent 6cf0ed3 commit 0e381b3

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

server/lib/classes/db_mysql.inc.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class db
4141
var $errorNumber = 0; // last error number
4242
var $errorMessage = ""; // last error message
4343
var $errorLocation = "";// last error location
44-
var $show_error_messages = false;
44+
var $show_error_messages = true;
4545

4646
// constructor
4747
function db()
@@ -58,13 +58,15 @@ function db()
5858
// error handler
5959
function updateError($location)
6060
{
61+
global $app;
6162
$this->errorNumber = mysql_errno();
6263
$this->errorMessage = mysql_error();
6364
$this->errorLocation = $location;
64-
if($this->errorNumber && $this->show_error_messages)
65+
if($this->errorNumber && $this->show_error_messages && method_exists($app,'log'))
6566
{
66-
echo('<br /><b>'.$this->errorLocation.'</b><br />'.$this->errorMessage);
67-
flush();
67+
// echo('<br /><b>'.$this->errorLocation.'</b><br />'.$this->errorMessage);
68+
$app->log($this->errorLocation." ".$this->errorMessage,LOGLEVEL_WARN);
69+
//flush();
6870
}
6971
}
7072

@@ -75,7 +77,7 @@ function connect()
7577
$this->linkId = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
7678
if(!$this->linkId)
7779
{
78-
$this->updateError('DB::connect()<br />mysql_connect');
80+
$this->updateError('DB::connect()-> mysql_connect');
7981
return false;
8082
}
8183
}
@@ -90,11 +92,11 @@ function query($queryString)
9092
}
9193
if(!mysql_select_db($this->dbName, $this->linkId))
9294
{
93-
$this->updateError('DB::connect()<br />mysql_select_db');
95+
$this->updateError('DB::connect()-> mysql_select_db');
9496
return false;
9597
}
9698
$this->queryId = @mysql_query($queryString, $this->linkId);
97-
$this->updateError('DB::query('.$queryString.')<br />mysql_query');
99+
$this->updateError('DB::query('.$queryString.') -> mysql_query');
98100
if(!$this->queryId)
99101
{
100102
return false;
@@ -132,7 +134,7 @@ function queryOneRecord($queryString)
132134
function nextRecord()
133135
{
134136
$this->record = mysql_fetch_assoc($this->queryId);
135-
$this->updateError('DB::nextRecord()<br />mysql_fetch_array');
137+
$this->updateError('DB::nextRecord()-> mysql_fetch_array');
136138
if(!$this->record || !is_array($this->record))
137139
{
138140
return false;

server/server.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
$app->log("Set Lock: ".$conf["temppath"].$conf["fs_div"].".ispconfig_lock", LOGLEVEL_DEBUG);
6969

7070

71-
if($app->dbmaster->connect()) {
71+
if($app->db->connect() && $app->dbmaster->connect()) {
7272

7373
// get the dalaog_id of the last performed record
7474
$server_db_record = $app->dbmaster->queryOneRecord("SELECT updated, config FROM server WHERE server_id = ".$conf["server_id"]);
@@ -114,7 +114,11 @@
114114
$app->plugins->loadPlugins('core');
115115
}
116116
} else {
117-
$app->log("Unable to connect to master server.",LOGLEVEL_WARN);
117+
if(!$app->db->connect()) {
118+
$app->log("Unable to connect to local server.".$app->db->errorMessage,LOGLEVEL_WARN);
119+
} else {
120+
$app->log("Unable to connect to master server.".$app->dbmaster->errorMessage,LOGLEVEL_WARN);
121+
}
118122
}
119123

120124
// Remove lock

0 commit comments

Comments
 (0)