BUGFIX Ensure that the current DB connection is properly closed when scripts stop executing (applies to mssql_close and sqlsrv_close)

This commit is contained in:
Sean Harvey 2009-07-20 07:23:38 +00:00
parent 333ac5f26a
commit b6a0c4f8a4

View File

@ -65,12 +65,12 @@ class MSSQLDatabase extends Database {
} else { } else {
user_error("Neither the mssql_connect() nor the sqlsrv_connect() functions are available. Please install the PHP native mssql module, or the Microsoft-provided sqlsrv module.", E_USER_ERROR); user_error("Neither the mssql_connect() nor the sqlsrv_connect() functions are available. Please install the PHP native mssql module, or the Microsoft-provided sqlsrv module.", E_USER_ERROR);
} }
if($this->mssql) { if($this->mssql) {
$this->dbConn = mssql_connect($parameters['server'], $parameters['username'], $parameters['password']); $this->dbConn = mssql_connect($parameters['server'], $parameters['username'], $parameters['password']);
} else { } else {
$this->dbConn = sqlsrv_connect($parameters['server'], array( $this->dbConn = sqlsrv_connect($parameters['server'], array(
'UID' => $parameters['username'], 'UID' => $parameters['username'],
'PWD' => $parameters['password'], 'PWD' => $parameters['password'],
)); ));
} }
@ -88,6 +88,16 @@ class MSSQLDatabase extends Database {
} }
} }
public function __destruct() {
if($this->dbConn) {
if(function_exists('mssql_close')) {
mssql_close($this->dbConn);
} elseif(function_exists('sqlsrv_close')) {
sqlsrv_close($this->dbConn);
}
}
}
/** /**
* Throw a database error * Throw a database error
*/ */