[pLog-svn] r989 - in plog/trunk/class: config database

oscar at devel.plogworld.net oscar at devel.plogworld.net
Tue Feb 8 08:19:50 GMT 2005


Author: oscar
Date: 2005-02-08 08:19:50 +0000 (Tue, 08 Feb 2005)
New Revision: 989

Modified:
   plog/trunk/class/config/configdbstorage.class.php
   plog/trunk/class/database/db.class.php
Log:
fixed issue 219 (http://bugs.plogworld.net/view.php?id=219) and now we even saved some unneeded code!


Modified: plog/trunk/class/config/configdbstorage.class.php
===================================================================
--- plog/trunk/class/config/configdbstorage.class.php	2005-02-08 07:37:12 UTC (rev 988)
+++ plog/trunk/class/config/configdbstorage.class.php	2005-02-08 08:19:50 UTC (rev 989)
@@ -6,8 +6,6 @@
 
 
 	include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
-	include_once( PLOG_CLASS_PATH."class/database/adodb/adodb.inc.php" );
-	include_once( PLOG_CLASS_PATH."class/config/configabstractstorage.class.php" );
 	include_once( PLOG_CLASS_PATH."class/config/configfilestorage.class.php" );
 
 
@@ -36,10 +34,6 @@
     {
 
     	// information needed to connect to the db server
-    	var $_dbHost;
-        var $_dbPassword;
-        var $_dbUsername;
-        var $_dbDatabase;
         var $_dbPrefix;
 
         // ADOdb handler
@@ -47,37 +41,22 @@
 
         // array used to store the options
         var $_data;
+        
+        // database prefix
+        var $_dbPrefix;
 
         /**
          * Connects to the database using the parameters in the config file.
          *
          */
     	function ConfigDbStorage( $params = null )
-        {
-        	$this->ConfigAbstractStorage( $params );
+        {            
+            // initialize the connection
+            $this->_db =& Db::getDb();
+            // get the prefix
+            $this->_dbPrefix = Db::getPrefix();
 
-            // its quite ironic that the database storage backend
-            // depends on the file storage backend to retrieve some data :)
-            $fileConfig = new ConfigFileStorage();
-            $this->_dbHost     = $fileConfig->getValue( "db_host" );
-            $this->_dbPassword = $fileConfig->getValue( "db_password" );
-            $this->_dbUsername = $fileConfig->getValue( "db_username" );
-            $this->_dbDatabase = $fileConfig->getValue( "db_database" );
-            $this->_dbPrefix   = $fileConfig->getValue( "db_prefix" );
-
-            $this->_db = NewADOConnection( "mysql" );
-            //print($this->_dbUsername);
-            if( $this->_db->PConnect( $this->_dbHost, $this->_dbUsername, $this->_dbPassword, $this->_dbDatabase )) {
-            	// just in case, forcing to use indexing by field name instead of
-            	// by field number
-                $this->_db->SetFetchMode( ADODB_FETCH_ASSOC );
-            }
-            else {
-            	// quit because this is very critical
-                throw( new Exception( "Could not connect to the database. Please check the database settings" ));
-                die();
-            }
-
+            // and finally, load the whole data
             $this->_loadData();
         }
 
@@ -100,6 +79,7 @@
 
             // this is a severe error
             if( !$result ) {
+	            print($this->_db->ErrorMsg());
             	throw( new Exception( "There was an error loading the configuration data from the database. And this is bad..." ));
                 die();
             }

Modified: plog/trunk/class/database/db.class.php
===================================================================
--- plog/trunk/class/database/db.class.php	2005-02-08 07:37:12 UTC (rev 988)
+++ plog/trunk/class/database/db.class.php	2005-02-08 08:19:50 UTC (rev 989)
@@ -12,7 +12,8 @@
     /**
      * Provides a singleton for accessing the db.
      */
-	class Db extends Object {
+	class Db extends Object 
+	{
 
 		function Db()
 		{
@@ -57,6 +58,19 @@
 
             return $dbcache;
 		}
+		
+		/**
+		 * returns the prefix as configured for this database connection
+		 *
+		 * @return A string containing the database prefix
+		 * @static
+		 */
+		function getPrefix()
+		{
+			$fileConfig = new ConfigFileStorage();
+			$prefix = $fileConfig->getValue( "db_prefix" );
+			return( $prefix );	
+		}
 
 		/**
 		 * Prepares a string for an SQL query by escaping apostrophe




More information about the pLog-svn mailing list