[pLog-svn] r1727 - plog/branches/plog-1.1-ben/class/dao

ork at devel.plogworld.net ork at devel.plogworld.net
Tue Apr 5 11:02:41 GMT 2005


Author: ork
Date: 2005-04-05 11:02:41 +0000 (Tue, 05 Apr 2005)
New Revision: 1727

Modified:
   plog/branches/plog-1.1-ben/class/dao/model.class.php
Log:
moved all db stuff to _initializeDb()


Modified: plog/branches/plog-1.1-ben/class/dao/model.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/dao/model.class.php	2005-04-05 10:10:33 UTC (rev 1726)
+++ plog/branches/plog-1.1-ben/class/dao/model.class.php	2005-04-05 11:02:41 UTC (rev 1727)
@@ -61,23 +61,15 @@
 	{
 
 		var $_db;		
-        var $_prefix;
+        var $_prefix = null;
+        var $_dbInitialized =  false;
 
         /**
          * So far, it only initializes the connection to the database, using the ADOdb API.
          */
 		function Model()
         {
-            include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
-
             $this->Object();
-
-            $this->_db =& Db::getDb();
-
-            // fetch the database prefix            
-            $this->_prefix = Db::getPrefix();
-
-			$this->_db->debug=DAO_DEBUG_ENABLED;
         }
 
 		/**
@@ -91,6 +83,8 @@
 		 */        
         function Execute( $query, $page = DEFAULT_PAGING_ENABLED, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
         {
+            $this->_initializeDb();
+
 			// if paging is enabled...
 			if( $page > DEFAULT_PAGING_ENABLED ) {
 				$start = (($page - 1) * $itemsPerPage);
@@ -151,7 +145,13 @@
 		 */
         function getPrefix()
         {
-        	return $this->_prefix;
+            if ( $this->_prefix == null ) {
+                include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+
+                $this->_prefix = Db::getPrefix();
+            }
+
+            return $this->_prefix;
         }
 
 		/**
@@ -180,5 +180,23 @@
 
 			return $total;
 		}
+
+        /**
+         * Initialize the Db and set the table-prefix.
+         */
+        function _initializeDb()
+        {
+            if ( !$this->_dbInitialized ) {
+                include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+
+                $this->_db =& Db::getDb();
+
+                // fetch the database prefix            
+                $this->getPrefix();
+                // $this->_db->debug=DAO_DEBUG_ENABLED;
+
+                $this->_dbInitialized = true;
+            }
+        }
     }
 ?>




More information about the pLog-svn mailing list