From ee85e4d08ddb7e2ec03904c0893cf3dd464125fb Mon Sep 17 00:00:00 2001 From: Paul Arthur Date: Mon, 27 May 2013 20:32:02 -0400 Subject: Change Dba::error() and audit its callers Will hopefully return more useful information during installation, which is the only place it's actually used and useful. --- lib/class/dba.class.php | 12 +++++++----- lib/class/session.class.php | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'lib/class') diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php index 55608f76..96b313bc 100644 --- a/lib/class/dba.class.php +++ b/lib/class/dba.class.php @@ -39,6 +39,7 @@ class Dba { public static $stats = array('query'=>0); private static $_sql; + private static $_error; private static $config; /** @@ -89,10 +90,12 @@ class Dba { self::$stats['query']++; if (!$stmt) { + self::$_error = json_encode($dbh->errorInfo()); debug_event('Dba', 'Error: ' . json_encode($dbh->errorInfo()), 1); self::disconnect(); } else if ($stmt->errorCode() && $stmt->errorCode() != '00000') { + self::$_error = json_encode($stmt->errorInfo()); debug_event('Dba', 'Error: ' . json_encode($stmt->errorInfo()), 1); self::disconnect(); return false; @@ -248,6 +251,7 @@ class Dba { $dbh = new PDO($dsn, $username, $password); } catch (PDOException $e) { + self::$_error = $e->getMessage(); debug_event('Dba', 'Connection failed: ' . $e->getMessage(), 1); return null; } @@ -267,6 +271,7 @@ class Dba { } if ($dbh->exec('USE `' . $database . '`') === false) { + self::$_error = json_encode($dbh->errorInfo()); debug_event('Dba', 'Unable to select database ' . $database . ': ' . json_encode($dbh->errorInfo()), 1); } @@ -286,6 +291,7 @@ class Dba { $dbh = self::_connect(); if (!$dbh || $dbh->errorCode()) { + self::$_error = json_encode($dbh->errorInfo()); return false; } @@ -390,11 +396,7 @@ class Dba { * this returns the error of the db */ public static function error() { - $dbh = self::dbh(); - if ($dbh) { - return $dbh->errorCode(); - } - return false; + return self::$_error; } /** diff --git a/lib/class/session.class.php b/lib/class/session.class.php index 0f6540fc..f34b7be7 100644 --- a/lib/class/session.class.php +++ b/lib/class/session.class.php @@ -80,7 +80,7 @@ class Session { $sql = 'UPDATE `session` SET `value` = ?, `expire` = ? WHERE `id` = ?'; $db_results = Dba::read($sql, array($value, $expire, $key)); - debug_event('session', 'Writing to ' . $key . ' with expire ' . $expire . ' [' . Dba::error() . ']', 6); + debug_event('session', 'Writing to ' . $key . ' with expiration ' . $expire, 6); return true; } -- cgit