Permalink
Browse files

Added JDatabaseDriver::disconnect() to support disconnecting from the

database cleanly.
  • Loading branch information...
1 parent e27be38 commit 836bb46579e32e198202ec37cda8268355acb3b0 @robschley robschley committed May 6, 2012
@@ -397,6 +397,15 @@ public function __construct($options)
abstract public function connected();
/**
+ * Disconnects the database.
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
+ abstract public function disconnect();
+
+ /**
* Drops a table from the database.
*
* @param string $table The name of the database table to drop.
@@ -74,6 +74,19 @@ public function __construct($options)
}
/**
+ * Destructor.
+ *
+ * @since 12.1
+ */
+ public function __destruct()
+ {
+ if (is_resource($this->connection))
+ {
+ mysql_close($this->connection);
+ }
+ }
+
+ /**
* Connects to the database if needed.
*
* @return void Returns void if the database connected successfully.
@@ -114,16 +127,18 @@ public function connect()
}
/**
- * Destructor.
+ * Disconnects the database.
+ *
+ * @return void
*
* @since 12.1
*/
- public function __destruct()
+ public function disconnect()
{
- if (is_resource($this->connection))
- {
- mysql_close($this->connection);
- }
+ // Close the connection.
+ mysql_close($this->connection);
+
+ $this->connection = null;
}
/**
@@ -173,7 +188,7 @@ public function connected()
{
if (is_resource($this->connection))
{
- return mysql_ping($this->connection);
+ return @mysql_ping($this->connection);
}
return false;
@@ -50,6 +50,19 @@ public function __construct($options)
}
/**
+ * Destructor.
+ *
+ * @since 12.1
+ */
+ public function __destruct()
+ {
+ if (is_callable($this->connection, 'close'))
+ {
+ mysqli_close($this->connection);
+ }
+ }
+
+ /**
* Connects to the database if needed.
*
* @return void Returns void if the database connected successfully.
@@ -121,16 +134,21 @@ public function connect()
}
/**
- * Destructor.
+ * Disconnects the database.
+ *
+ * @return void
*
* @since 12.1
*/
- public function __destruct()
+ public function disconnect()
{
+ // Close the connection.
if (is_callable($this->connection, 'close'))
{
mysqli_close($this->connection);
}
+
+ $this->connection = null;
}
/**
@@ -64,6 +64,17 @@ public function __construct($options)
}
/**
+ * Destructor.
+ *
+ * @since 12.1
+ */
+ public function __destruct()
+ {
+ $this->freeResult();
+ unset($this->connection);
+ }
+
+ /**
* Connects to the database if needed.
*
* @return void Returns void if the database connected successfully.
@@ -84,12 +95,15 @@ public function connect()
}
/**
- * Destructor.
+ * Disconnects the database.
+ *
+ * @return void
*
* @since 12.1
*/
- public function __destruct()
+ public function disconnect()
{
+ // Close the connection.
$this->freeResult();
unset($this->connection);
}
@@ -84,6 +84,17 @@ public function __construct($options)
}
/**
+ * Destructor.
+ *
+ * @since 12.1
+ */
+ public function __destruct()
+ {
+ $this->freeResult();
+ unset($this->connection);
+ }
+
+ /**
* Connects to the database if needed.
*
* @return void Returns void if the database connected successfully.
@@ -290,11 +301,13 @@ public function connect()
}
/**
- * Destructor.
+ * Disconnects the database.
+ *
+ * @return void
*
* @since 12.1
*/
- public function __destruct()
+ public function disconnect()
{
$this->freeResult();
unset($this->connection);
@@ -78,6 +78,19 @@ public function __construct( $options )
}
/**
+ * Database object destructor
+ *
+ * @since 12.1
+ */
+ public function __destruct()
+ {
+ if (is_resource($this->connection))
+ {
+ pg_close($this->connection);
+ }
+ }
+
+ /**
* Connects to the database if needed.
*
* @return void Returns void if the database connected successfully.
@@ -112,16 +125,21 @@ public function connect()
}
/**
- * Database object destructor
+ * Disconnects the database.
*
- * @since 12.1
+ * @return void
+ *
+ * @since 12.1
*/
- public function __destruct()
+ public function disconnect()
{
+ // Close the connection.
if (is_resource($this->connection))
{
pg_close($this->connection);
}
+
+ $this->connection = null;
}
/**
@@ -63,6 +63,19 @@ public function __destruct()
}
/**
+ * Disconnects the database.
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
+ public function disconnect()
+ {
+ $this->freeResult();
+ unset($this->connection);
+ }
+
+ /**
* Drops a table from the database.
*
* @param string $tableName The name of the database table to drop.
@@ -86,6 +86,19 @@ public function __construct($options)
}
/**
+ * Destructor.
+ *
+ * @since 12.1
+ */
+ public function __destruct()
+ {
+ if (is_resource($this->connection))
+ {
+ sqlsrv_close($this->connection);
+ }
+ }
+
+ /**
* Connects to the database if needed.
*
* @return void Returns void if the database connected successfully.
@@ -131,16 +144,21 @@ public function connect()
}
/**
- * Destructor.
+ * Disconnects the database.
+ *
+ * @return void
*
* @since 12.1
*/
- public function __destruct()
+ public function disconnect()
{
+ // Close the connection.
if (is_resource($this->connection))
{
sqlsrv_close($this->connection);
}
+
+ $this->connection = null;
}
/**
@@ -37,6 +37,7 @@ public static function create($test, $nullDate = '0000-00-00 00:00:00', $dateFor
$methods = array(
'connect',
'connected',
+ 'disconnect',
'dropTable',
'escape',
'execute',
@@ -63,29 +63,29 @@ public function connect()
return true;
}
-
/**
-
* Determines if the connection to the server is active.
-
*
-
* @return boolean True if connected to the database engine.
-
*
-
* @since 11.4
-
*/
-
public function connected()
-
{
-
return true;
-
}
+ /**
+ * Disconnects the database.
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
+ public function disconnect()
+ {
+ return;
+ }
/**
* Drops a table from the database.

0 comments on commit 836bb46

Please sign in to comment.