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

Source for file DB.php

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

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