From 0fd884340965af54986bd77f1f1e38bebec3b3db Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 30 Jul 2007 17:23:12 +0000 Subject: guarantee mysql_error in fatals --- it_dbi.class | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/it_dbi.class b/it_dbi.class index 5666d28..eb81081 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -77,7 +77,7 @@ function it_dbi($config = array(), $query = null) $this->_connect(); if (!($tables = mysql_list_tables($this->_db, $this->_link))) - $this->_fatal("it_dbi(): can't list on tables \"$this->_db\": " . mysql_error($this->_link)); + $this->_fatal("it_dbi(): can't list on tables \"$this->_db\""); for ($i = 0; $i < mysql_num_rows($tables); $i++) $this->createclass(mysql_tablename($tables, $i)); @@ -114,10 +114,10 @@ function _connect() } if (!$this->_link) - $this->_fatal("it_dbi(): can't create DB link (mysql_connect $this->_server, $this->_db): " . mysql_error()); + $this->_fatal("it_dbi(): can't create DB link (mysql_connect $this->_server, $this->_db)"); if (!(@mysql_select_db($this->_db, $this->_link))) - $this->_fatal("it_dbi(): can't select database \"$this->_db\": " . mysql_error($this->_link)); + $this->_fatal("it_dbi(): can't select database \"$this->_db\""); $GLOBALS['it_dbi_link'][$this->_dbid] = $this->_link; } @@ -133,7 +133,7 @@ function createclass($table) $classname = "$this->_classprefix$table"; if (!($result = @mysql_list_fields($this->_db, $table, $this->_link))) - $this->_fatal("it_dbi(): can't list fields \"$this->_db\": " . mysql_error($this->_link)); + $this->_fatal("it_dbi(): can't list fields \"$this->_db\""); for ($fields=array(), $j=0; $j < mysql_num_fields($result); $j++) { @@ -308,7 +308,10 @@ function _where($params='', $sql='', $omit_where=false) */ function _fatal($text) { - it::fatal(get_class($this).'::'.$text); + if ($this->_link && ($t = mysql_error($this->_link))) + $mysql_error = ", mysql_error=$t"; + + it::fatal(get_class($this).'::'.$text . $mysql_error); /* NOT REACHED */ } @@ -379,9 +382,8 @@ function query($query) return false; $error = mysql_errno($this->_link).' ('.mysql_error($this->_link).')'; - $trace = debug_backtrace(); $res = mysql_fetch_row(mysql_query('select database()', $this->_link)); - $this->_fatal("query(\"$query\") on {$res[0]} failed: $error\nfile {$trace[1]['file']} line {$trace[1]['line']}"); + $this->_fatal("query(\"$query\") on {$res[0]} failed: $error"); } -- cgit v1.2.3