From e02f0c21f61f14fc9e7f8095db230afe7d8c7e6c Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Thu, 18 Feb 2010 00:14:30 +1300 Subject: [PATCH] AwlDB: Attempt some better error handling. --- inc/AwlDBDialect.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/inc/AwlDBDialect.php b/inc/AwlDBDialect.php index 0c4ca89d..8a1c62ae 100644 --- a/inc/AwlDBDialect.php +++ b/inc/AwlDBDialect.php @@ -15,6 +15,8 @@ * @compatibility Requires PHP 5.1 or later */ +if ( !defined('E_USER_ERROR') ) define('E_USER_ERROR',256); + /** * The AwlDBDialect class handles * @package awl @@ -59,9 +61,13 @@ class AwlDBDialect { $this->dialect = $matches[1]; } else { - trigger_error("Unsupported database connection '".$connection_string."'", E_USER_ERROR); + trigger_error("Unsupported database connection '".$connection_string."'",E_USER_ERROR); + } + try { + $this->db = new PDO( $connection_string, $dbuser, $dbpass, $options ); + } catch (PDOException $e) { + trigger_error("PDO connection error '".$connection_string."': ".$e->getMessage(),E_USER_ERROR); } - $this->db = new PDO( $connection_string, $dbuser, $dbpass, $options ); } @@ -71,7 +77,7 @@ class AwlDBDialect { */ function SetSearchPath( $search_path = null ) { if ( !isset($this->dialect) ) { - trigger_error("Unsupported database dialect", E_USER_ERROR); + trigger_error("Unsupported database dialect",E_USER_ERROR); } switch ( $this->dialect ) { @@ -103,6 +109,8 @@ class AwlDBDialect { $version .= preg_replace( '/^PostgreSQL (\d+\.\d+)\..*$/i', '$1', $row[0]); } break; + default: + return null; } $this->version = $version; return $version;