diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2012-09-12 12:45:20 +0200 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2012-09-12 12:47:33 +0200 |
commit | e31dfb643a2b70b1ae7dc467b379fb2026709341 (patch) | |
tree | 4cc78680f4c335ba0eca1d7e331d292a444dfc16 /lib/db.php | |
parent | df528cfe95a8545605248465c60fbb18f60fb557 (diff) | |
download | nextcloud-server-e31dfb643a2b70b1ae7dc467b379fb2026709341.tar.gz nextcloud-server-e31dfb643a2b70b1ae7dc467b379fb2026709341.zip |
add getErrorMessage to OC_DB
Diffstat (limited to 'lib/db.php')
-rw-r--r-- | lib/db.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/db.php b/lib/db.php index ee69e5f8299..4317f798484 100644 --- a/lib/db.php +++ b/lib/db.php @@ -649,6 +649,30 @@ class OC_DB { return false; } } + + /** + * returns the error code and message as a string for logging + * works with MDB2 and PDOException + * @param mixed $error + * @return string + */ + public static function getErrorMessage($error) { + if ( self::$backend==self::BACKEND_MDB2 and PEAR::isError($error) ) { + $msg = $error->getCode() . ': ' . $error->getMessage(); + if (defined('DEBUG') && DEBUG) { + $msg .= '(' . $error->getDebugInfo() . ')'; + } + } elseif (self::$backend==self::BACKEND_PDO and self::$PDO) { + $msg = self::$PDO->errorCode() . ': '; + $errorInfo = self::$PDO->errorInfo(); + if (is_array($errorInfo)) { + $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; + $msg .= 'Driver Code = '.$errorInfo[1] . ', '; + $msg .= 'Driver Message = '.$errorInfo[2]; + } + } + return $msg; + } } /** |