Skip to content

Commit

Permalink
Extended the PDO class with connection information in a property
Browse files Browse the repository at this point in the history
  • Loading branch information
sjstoelting committed Apr 5, 2012
1 parent ac1980e commit 40fd9b0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pdo/ez_sql_pdo.php
Expand Up @@ -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 ) {
Expand All @@ -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

/**
Expand Down Expand Up @@ -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

0 comments on commit 40fd9b0

Please sign in to comment.