summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2013-05-27 20:32:02 -0400
committerPaul Arthur <paul.arthur@flowerysong.com>2013-05-27 20:32:02 -0400
commitee85e4d08ddb7e2ec03904c0893cf3dd464125fb (patch)
tree8b0065dc408466724ed93c726bf10dabe1a1b5d0 /lib
parent914c903250de4837d3bf6e77e496c2a3ece5f638 (diff)
downloadampache-ee85e4d08ddb7e2ec03904c0893cf3dd464125fb.tar.gz
ampache-ee85e4d08ddb7e2ec03904c0893cf3dd464125fb.tar.bz2
ampache-ee85e4d08ddb7e2ec03904c0893cf3dd464125fb.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/class/dba.class.php12
-rw-r--r--lib/class/session.class.php2
-rw-r--r--lib/install.lib.php14
3 files changed, 15 insertions, 13 deletions
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;
}
diff --git a/lib/install.lib.php b/lib/install.lib.php
index ef300101..dfaba46e 100644
--- a/lib/install.lib.php
+++ b/lib/install.lib.php
@@ -121,7 +121,7 @@ function install_insert_db($db_user = null, $db_pass = null, $overwrite = false)
}
if (!Dba::check_database()) {
- Error::add('general', sprintf(T_('Error: Unable to make Database Connection %s'), Dba::error()));
+ Error::add('general', sprintf(T_('Error: Unable to make database connection: %s'), Dba::error()));
return false;
}
@@ -137,7 +137,7 @@ function install_insert_db($db_user = null, $db_pass = null, $overwrite = false)
elseif (!$db_exists) {
$sql = 'CREATE DATABASE `' . $database . '`';
if (!Dba::write($sql)) {
- Error::add('general',sprintf(T_('Error: Unable to Create Database %s'), Dba::error()));
+ Error::add('general',sprintf(T_('Error: Unable to create database: %s'), Dba::error()));
return false;
}
} // if db can't be selected
@@ -146,7 +146,7 @@ function install_insert_db($db_user = null, $db_pass = null, $overwrite = false)
Dba::write($sql);
$sql = 'CREATE DATABASE `' . $database . '`';
if (!Dba::write($sql)) {
- Error::add('general', sprintf(T_('Error: Unable to Create Database %s'), Dba::error()));
+ Error::add('general', sprintf(T_('Error: Unable to create database: %s'), Dba::error()));
return false;
}
} // end if selected and overwrite
@@ -163,7 +163,7 @@ function install_insert_db($db_user = null, $db_pass = null, $overwrite = false)
}
$sql .= "IDENTIFIED BY '" . Dba::escape($db_pass) . "' WITH GRANT OPTION";
if (!Dba::write($sql)) {
- Error::add('general', sprintf(T_('Error: Unable to Insert %1$s with permissions to %2$s on %3$s %4$s'), $db_user, $database, $hostname, Dba::error()));
+ Error::add('general', sprintf(T_('Error: Unable to create user %1$s with permissions to %2$s on %3$s: %4$s'), $db_user, $database, $db_host, Dba::error()));
return false;
}
} // end if we are creating a user
@@ -257,12 +257,12 @@ function install_create_account($username, $password, $password2) {
}
if (!Dba::check_database()) {
- Error::add('general', sprintf(T_('Database Connection Failed: %s'), Dba::error()));
+ Error::add('general', sprintf(T_('Database connection failed: %s'), Dba::error()));
return false;
}
if (!Dba::check_database_inserted()) {
- Error::add('general', sprintf(T_('Database Select Failed: %s'), Dba::error()));
+ Error::add('general', sprintf(T_('Database select failed: %s'), Dba::error()));
return false;
}
@@ -272,7 +272,7 @@ function install_create_account($username, $password, $password2) {
$insert_id = User::create($username,'Administrator','',$password,'100');
if (!$insert_id) {
- Error::add('general', sprintf(T_('Insert of Base User Failed %s'), Dba::error()));
+ Error::add('general', sprintf(T_('Administrative user creation failed: %s'), Dba::error()));
return false;
}