Permalink
Browse files

Merge pull request #1189 from robschley/disconnect

Added JDatabaseDriver::disconnect() to support disconnecting from the database cleanly.
  • Loading branch information...
pasamio committed May 7, 2012
2 parents e27be38 + 836bb46 commit 1ef2ad6b6d2b230105e4a3aa5ca043e122f2d275
@@ -396,6 +396,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.
*
@@ -73,6 +73,19 @@ public function __construct($options)
parent::__construct($options);
}
+ /**
+ * Destructor.
+ *
+ * @since 12.1
+ */
+ public function __destruct()
+ {
+ if (is_resource($this->connection))
+ {
+ mysql_close($this->connection);
+ }
+ }
+
/**
* Connects to the database if needed.
*
@@ -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;
@@ -49,6 +49,19 @@ public function __construct($options)
parent::__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.
*
@@ -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;
}
/**
@@ -63,6 +63,17 @@ public function __construct($options)
parent::__construct($options);
}
+ /**
+ * Destructor.
+ *
+ * @since 12.1
+ */
+ public function __destruct()
+ {
+ $this->freeResult();
+ unset($this->connection);
+ }
+
/**
* Connects to the database if needed.
*
@@ -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);
}
@@ -83,6 +83,17 @@ public function __construct($options)
parent::__construct($options);
}
+ /**
+ * Destructor.
+ *
+ * @since 12.1
+ */
+ public function __destruct()
+ {
+ $this->freeResult();
+ unset($this->connection);
+ }
+
/**
* Connects to the database if needed.
*
@@ -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);
@@ -77,6 +77,19 @@ public function __construct( $options )
parent::__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.
*
@@ -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;
}
/**
@@ -62,6 +62,19 @@ public function __destruct()
unset($this->connection);
}
+ /**
+ * Disconnects the database.
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
+ public function disconnect()
+ {
+ $this->freeResult();
+ unset($this->connection);
+ }
+
/**
* Drops a table from the database.
*
@@ -85,6 +85,19 @@ public function __construct($options)
parent::__construct($options);
}
+ /**
+ * Destructor.
+ *
+ * @since 12.1
+ */
+ public function __destruct()
+ {
+ if (is_resource($this->connection))
+ {
+ sqlsrv_close($this->connection);
+ }
+ }
+
/**
* Connects to the database if needed.
*
@@ -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 1ef2ad6

Please sign in to comment.