From 38f84f702bd88b19caa4a13324fbc483e362e3bb Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 20 Dec 2006 01:13:22 +0000 Subject: [PATCH] We can now get DB errors without notices or warnings --- Db.php | 21 +++++++++++++-------- DbMySql.php | 22 ++++++++++++++++++++++ DbMySqlI.php | 22 ++++++++++++++++++++++ DbPostgreSql.php | 44 ++++++++++++++++++++++---------------------- 4 files changed, 79 insertions(+), 30 deletions(-) diff --git a/Db.php b/Db.php index 246f0ca..d8d1d14 100644 --- a/Db.php +++ b/Db.php @@ -421,6 +421,17 @@ abstract class BSDb */ protected abstract function _affectedRows($result); + // ################################################################### + /** + * Returns the errror number + */ + public abstract function _errorNumber(); + + /** + * Returns the error string + */ + public abstract function _errorString(); + // ################################################################### /** * Sends the command to start a transaction. This command should never @@ -463,18 +474,12 @@ abstract class BSDb { if ($this->showerrors) { - if ($this->dblink) - { - $this->errnum = call_user_func($this->commands['error_num'], $this->dblink); - $this->errstr = call_user_func($this->commands['error_str'], $this->dblink); - } - $style['code'] = 'font-family: \'Courier New\', Courier, mono; font-size: 11px;'; $message_prepped = "
\n

"; $message_prepped .= "\n\t» Query:\n

" . htmlspecialchars($this->querystr) ."
\n
"; - $message_prepped .= "\n\t» Error Number: " . $this->errnum . "\n
"; - $message_prepped .= "\n\t» Error Message: " . $this->errstr . "\n
"; + $message_prepped .= "\n\t» Error Number: " . $this->_errorNumber() . "\n
"; + $message_prepped .= "\n\t» Error Message: " . $this->_errorString() . "\n
"; $message_prepped .= "\n\t» Additional Notes: " . $message . "\n
"; $message_prepped .= "\n\t» File: " . $_SERVER['PHP_SELF'] . "\n"; $message_prepped .= "\n

\n
"; diff --git a/DbMySql.php b/DbMySql.php index 2c1c3d1..2f3527a 100644 --- a/DbMySql.php +++ b/DbMySql.php @@ -225,6 +225,28 @@ class BSDbMySql extends BSDb { $this->query("COMMIT"); } + + // ################################################################### + /** + * Returns the error number + * + * @return integer Error number + */ + public function _errorNumber() + { + return mysql_errno($this->dblink); + } + + // ################################################################### + /** + * Returns the error string + * + * @return string Error string + */ + public function _errorString() + { + return mysql_error($this->dblink); + } } /*=====================================================================*\ diff --git a/DbMySqlI.php b/DbMySqlI.php index f2557c9..161f008 100644 --- a/DbMySqlI.php +++ b/DbMySqlI.php @@ -197,6 +197,28 @@ class BSDbMySqlI extends BSDb { $this->query("COMMIT"); } + + // ################################################################### + /** + * Returns the error number + * + * @return integer Error number + */ + public function _errorNumber() + { + return mysqli_errno($this->dblink); + } + + // ################################################################### + /** + * Returns the error string + * + * @return string Error string + */ + public function _errorString() + { + return mysqli_error($this->dblink); + } } /*=====================================================================*\ diff --git a/DbPostgreSql.php b/DbPostgreSql.php index 6189471..eae0ca4 100644 --- a/DbPostgreSql.php +++ b/DbPostgreSql.php @@ -41,28 +41,6 @@ require_once('ISSO/Db.php'); */ class BSDbPostgreSql extends BSDb { - /** - * Command mapping list - * @var array - */ - protected $commands = array( - 'pconnect' => '$this->command_pg_pconnect', - 'connect' => '$this->command_pg_connect', - 'query' => 'pg_query', - 'error_num' => '$this->command_error_num', - 'error_str' => '$this->command_error_str', - 'escape_string' => '$this->command_pg_escape_string', - 'escape_binary' => 'pg_escape_bytea', - 'unescape_binary' => 'pg_unescape_bytea', - 'fetch_assoc' => 'pg_fetch_assoc', - 'fetch_row' => 'pg_fetch_row', - 'fetch_object' => 'pg_fetch_object', - 'free_result' => 'pg_free_result', - 'insert_id' => '%link', // how do we support this...? - 'num_rows' => 'pg_num_rows', - 'affected_rows' => 'pg_affected_rows' - ); - /** * Port number to connect to * @var integer @@ -238,6 +216,28 @@ class BSDbPostgreSql extends BSDb { $this->query("COMMIT"); } + + // ################################################################### + /** + * Returns the error number + * + * @return integer Error number + */ + public function _errorNumber() + { + return -1; + } + + // ################################################################### + /** + * Returns the error string + * + * @return string Error string + */ + public function _errorString() + { + return pg_last_error($this->dblink); + } } /*=====================================================================*\ -- 2.22.5