[Solar-svn] Revision 2890

pmjones at solarphp.com pmjones at solarphp.com
Thu Oct 18 08:34:52 CDT 2007


Solar_Sql_Adapter

* [BRK] Changed protected _connect() to public connect().

* [ADD] Method disconnect() to close database connection; thanks, Rodrigo Moraes.

fixes #96





Modified: trunk/Solar/Sql/Adapter.php
===================================================================
--- trunk/Solar/Sql/Adapter.php	2007-10-18 13:34:18 UTC (rev 2889)
+++ trunk/Solar/Sql/Adapter.php	2007-10-18 13:34:51 UTC (rev 2890)
@@ -289,7 +289,7 @@
      */
     public function getPdo()
     {
-        $this->_connect();
+        $this->connect();
         return $this->_pdo;
     }
     
@@ -337,7 +337,7 @@
      * @return void
      * 
      */
-    protected function _connect()
+    public function connect()
     {
         // if we already have a PDO object, no need to re-connect.
         if ($this->_pdo) {
@@ -395,6 +395,23 @@
     
     /**
      * 
+     * Closes the database connection.
+     * 
+     * This isn't generally necessary as PHP will automatically close the
+     * connection in the end of the script execution, but it can be useful
+     * to free resources when a script needs to connect tomultiple databases
+     * in sequence.
+     * 
+     * @return void
+     * 
+     */
+    public function disconnect()
+    {
+        $this->_pdo = null;
+    }
+    
+    /**
+     * 
      * Gets a full cache key.
      * 
      * @param string $key The partial cache key.
@@ -487,7 +504,7 @@
      */
     public function query($stmt, $data = array())
     {
-        $this->_connect();
+        $this->connect();
         
         // begin the profile time
         $before = microtime(true);
@@ -580,7 +597,7 @@
      */
     public function begin()
     {
-        $this->_connect();
+        $this->connect();
         $before = microtime(true);
         $result = $this->_pdo->beginTransaction();
         if ($this->_profiling) {
@@ -599,7 +616,7 @@
      */
     public function commit()
     {
-        $this->_connect();
+        $this->connect();
         $before = microtime(true);
         $result = $this->_pdo->commit();
         if ($this->_profiling) {
@@ -618,7 +635,7 @@
      */
     public function rollback()
     {
-        $this->_connect();
+        $this->connect();
         $before = microtime(true);
         $result = $this->_pdo->rollBack();
         if ($this->_profiling) {
@@ -1160,7 +1177,7 @@
             return $val;
         } else {
             // quote all other scalars
-            $this->_connect();
+            $this->connect();
             return $this->_pdo->quote($val);
         }
     }
@@ -1270,7 +1287,7 @@
      */
     public function lastInsertId($table = null, $col = null)
     {
-        $this->_connect();
+        $this->connect();
         return $this->_pdo->lastInsertId();
     }
     




More information about the Solar-svn mailing list