phpDocumentor ZNF
Business
[ class tree: ZNF ] [ index: ZNF ] [ all elements ]

Source for file MDB2.php

Documentation is available at MDB2.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4.  * PHP version 5
  5.  *
  6.  * This source file is subject to version 2.1 of the GNU Lesser General Public
  7.  * License, that is bundled with this package in the file COPYING, available
  8.  * through the world wide web at the following URI:
  9.  * http://www.gnu.org/copyleft/lesser.html.
  10.  *
  11.  * @package    ZNF
  12.  * @subpackage Business
  13.  * @author     Graziano Liberati <http://www.liberati.org>
  14.  * @copyright  2004-2007 The ZNF Development Team
  15.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  16.  * @version    SVN $Id: DB.php 9 2005-11-23 19:32:20Z freejay $
  17.  * @since      Release 0.7.9
  18.  * @link       http://www.zeronotice.org
  19.  */
  20.  
  21. require_once('MDB2.php');
  22. require_once('ZNF/Config/DBConfig.php');
  23.  
  24. /**
  25.  * The <i>ZNF_Business_DB</i> class extends the PEAR <i>DB</i> class.
  26.  *
  27.  * Connects to the database using the configuration taken from the database
  28.  * configuration file. Returns the <i>ZNF_Business_DB</i> object reference with
  29.  * a singleton pattern.
  30.  *
  31.  * @access     public
  32.  * @package    ZNF
  33.  * @subpackage Business
  34.  * @author     Graziano Liberati <http://www.liberati.org>
  35.  * @copyright  2004-2007 The ZNF Development Team
  36.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  37.  * @version    SVN $Id: DB.php 9 2005-11-23 19:32:20Z freejay $
  38.  * @since      Release 0.8.0
  39.  * @link       http://www.zeronotice.org
  40.  */
  41. class ZNF_Business_MDB2 extends MDB2
  42. {
  43.  
  44.     /**
  45.      * The database object reference.
  46.      *
  47.      * @access private
  48.      * @staticvar ZNF_Business_DB $_db 
  49.      */
  50.     static private $_db;
  51.  
  52.     /**
  53.      * Prefix used in the name of the database tables.
  54.      *
  55.      * @access private
  56.      * @staticvar string $_tablePrefix 
  57.      */
  58.     static private $_tablePrefix;
  59.  
  60.     /**
  61.      * Private constructor to avoid <i>ZNF_Business_DB</i> object creation.
  62.      *
  63.      * @access private
  64.      */
  65.     private function __construct()
  66.     {
  67.     }
  68.  
  69.     /**
  70.      * Private clonator to avoid <i>ZNF_Business_DB</i> object clonation.
  71.      *
  72.      * @access private
  73.      */
  74.     private function __clone()
  75.     {
  76.     }
  77.  
  78.     /**
  79.      * Returns the reference to the <i>ZNF_Business_DB</i> object with a singleton pattern.
  80.      *
  81.      * This object is shared by all the classes that require the access to the
  82.      * database.
  83.      *
  84.      * @static
  85.      * @access public
  86.      * @return ZNF_Business_DB 
  87.      */
  88.     static public function getInstance()
  89.     {
  90.         if (!(isset(self::$_db))) {
  91.             $dbConfig ZNF_Config_DBConfig::getInstance();
  92.             $dsn "{$dbConfig->getDbms()}://{$dbConfig->getUsername()}:{$dbConfig->getPassword()}@{$dbConfig->getHostname()}/{$dbConfig->getDbname()}";
  93.             self::$_db self::connect($dsn);
  94.  
  95.             if (self::isError(self::$_db)) {
  96.                 $translation new ZNF_Presentation_Translation('ZNF'$_SESSION['znf']['lang']);
  97.                 throw new ZNF_Business_MDB2Exception($translation->get('errorDbConnection'));
  98.             else {
  99.                 self::$_db->setFetchMode(MDB2_FETCHMODE_ASSOC);
  100.             }
  101.             self::$_tablePrefix $dbConfig->getTablePrefix();
  102.         }
  103.  
  104.         return self::$_db;
  105.     }
  106.  
  107.     /**
  108.      * Returns the prefix used in the name of the database tables.
  109.      *
  110.      * @static
  111.      * @access public
  112.      * @return string 
  113.      */
  114.     static public function getTablePrefix()
  115.     {
  116.         return self::$_tablePrefix;
  117.     }
  118.  
  119.     /**
  120.      * Destroys the <i>ZNF_Business_MDB2</i> object.
  121.      *
  122.      * @access public
  123.      */
  124.     public function __destruct()
  125.     {
  126.     }
  127.  
  128. }
  129.  
  130. /**
  131.  * <i>ZNF_Business_MDB2Exception</i> is the exception type for the <i>ZNF_Business_DB</i> class.
  132.  *
  133.  * <i>ZNF_Business_MDB2Exception</i> extends the <i>Exception</i> class of PHP5.
  134.  *
  135.  * @access     public
  136.  * @package    ZNF
  137.  * @subpackage Business
  138.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  139.  * @author     Graziano Liberati <http://www.liberati.org>
  140.  * @copyright  2004-2007 The ZNF Development Team
  141.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  142.  * @version    SVN $Id: DB.php 9 2005-11-23 19:32:20Z freejay $
  143.  * @since      Release 0.8.0
  144.  * @link       http://www.zeronotice.org
  145.  */
  146. class ZNF_Business_MDB2Exception extends Exception
  147. {
  148. }
  149.  
  150. ?>

Documentation generated on Wed, 14 Nov 2007 23:47:36 +0100 by phpDocumentor 1.4.0