From 40fd9b0519157b5bf92633ae6150ca994b7a4a7a Mon Sep 17 00:00:00 2001 From: sjstoelting Date: Thu, 5 Apr 2012 06:31:39 +0200 Subject: [PATCH] Extended the PDO class with connection information in a property --- pdo/ez_sql_pdo.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pdo/ez_sql_pdo.php b/pdo/ez_sql_pdo.php index 4d3fc5a..59203e5 100755 --- a/pdo/ez_sql_pdo.php +++ b/pdo/ez_sql_pdo.php @@ -87,7 +87,7 @@ public function __construct($dsn='', $user='', $password='') { * @return boolean */ public function connect($dsn='', $user='', $password='') { - $return_val = false; + $this->connected = false; // Must have a user and a password if ( ! $dsn || ! $user || ! $password ) { @@ -98,18 +98,16 @@ public function connect($dsn='', $user='', $password='') { // Establish PDO connection try { $this->dbh = new PDO($dsn, $user, $password); - $return_val = true; + $this->connected = true; } catch (PDOException $e) { $this->register_error($e->getMessage()); $this->show_errors ? trigger_error($e->getMessage(), E_USER_WARNING) : null; } - if ( $return_val ) { - // Set information about an established database connection - $this->isConnected = true; - } - return $return_val; + $this->isConnected = $this->connected; + + return $this->connected; } // connect /** @@ -337,7 +335,10 @@ public function query($query) { * Close the database connection */ public function disconnect(){ - $this->dbh = null; + if ($this->dbh) { + $this->dbh = null; + $this->connected = false; + } } // disconnect } // ezSQL_pdo