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

Source for file PDO.php

Documentation is available at PDO.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.  * @author     Markus Wigge <mwigge@marcant.net>
  16.  * @copyright  2004-2007 The ZNF Development Team
  17.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  18.  * @version    SVN $Id: DB.php 2 2005-10-20 15:54:16Z aronnax $
  19.  * @since      Release 0.7.7
  20.  * @link       http://www.zeronotice.org
  21.  */
  22.  
  23. require_once('ZNF/Config/DBConfig.php');
  24.  
  25. /**
  26.  * The <i>ZNF_Business_PDO</i> class uses the PHP Data Objects (PDO) extension.
  27.  *
  28.  * Connects to the database using the configuration taken from the database
  29.  * configuration file. Returns the <i>ZNF_Business_PDO</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.  * @author     Markus Wigge <mwigge@marcant.net>
  38.  * @copyright  2004-2007 The ZNF Development Team
  39.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  40.  * @version    SVN $Id: DB.php 2 2005-10-20 15:54:16Z aronnax $
  41.  * @since      Release 0.7.7
  42.  * @link       http://www.zeronotice.org
  43.  */
  44. {
  45.  
  46.     /**
  47.      * The database object reference.
  48.      *
  49.      * @access private
  50.      * @staticvar ZNF_Business_PDO $_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_PDO</i> object creation.
  64.      *
  65.      * @access private
  66.      */
  67.     private function __construct()
  68.     {
  69.     }
  70.  
  71.     /**
  72.      * Private clonator to avoid <i>ZNF_Business_PDO</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_PDO</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_PDO 
  89.      */
  90.     static public function getInstance()
  91.     {
  92.         if (!(isset(self::$_db))) {
  93.             $dbConfig ZNF_Config_DBConfig::getInstance();
  94.             $dsn "{$dbConfig->getDbms()}:host={$dbConfig->getHostname()};dbname={$dbConfig->getDbname()}";
  95.             try {
  96.                 self::$_db new PDO($dsn$dbConfig->getUsername()$dbConfig->getPassword());
  97.             }
  98.             catch (PDOException $e{
  99.                 $translation new ZNF_Presentation_Translation('ZNF'$_SESSION['znf']['lang']);
  100.                 throw new ZNF_Business_PDOException($translation->get('errorDbConnection'));
  101.             }
  102.             self::$_tablePrefix $dbConfig->getTablePrefix();
  103.         }
  104.  
  105.         return self::$_db;
  106.     }
  107.  
  108.     /**
  109.      * Returns the prefix used in the name of the database tables.
  110.      *
  111.      * @static
  112.      * @access public
  113.      * @return string 
  114.      */
  115.     static public function getTablePrefix()
  116.     {
  117.         return self::$_tablePrefix;
  118.     }
  119.  
  120.     /**
  121.      * Destroys the <i>ZNF_Business_PDO</i> object.
  122.      *
  123.      * @access public
  124.      */
  125.     public function __destruct()
  126.     {
  127.     }
  128.  
  129. }
  130.  
  131. /**
  132.  * <i>ZNF_Business_PDOException</i> is the exception type for the <i>ZNF_Business_PDO</i> class.
  133.  *
  134.  * <i>ZNF_Business_PDOException</i> extends the <i>Exception</i> class of PHP5.
  135.  *
  136.  * @access     public
  137.  * @package    ZNF
  138.  * @subpackage Business
  139.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  140.  * @author     Graziano Liberati <http://www.liberati.org>
  141.  * @copyright  2004-2007 The ZNF Development Team
  142.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  143.  * @version    SVN $Id: DB.php 2 2005-10-20 15:54:16Z aronnax $
  144.  * @since      Release 0.7.7
  145.  * @link       http://www.zeronotice.org
  146.  */
  147. class ZNF_Business_PDOException extends Exception
  148. {
  149. }
  150.  
  151. ?>

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