[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 /***************************************************** 3 * This file is part of Agora, web based content management system. 4 * 5 * Agora is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * 9 * Agora is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details (file "COPYING"). 13 * 14 * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière. 15 * List of authors detailed in "copyright_fr.html" file. 16 * E-mail : agora@sig.premier-ministre.gouv.fr 17 * Web site : http://www.agora.gouv.fr 18 *****************************************************/ 19 // Singleton 20 // $Id$ 21 22 class DBManager { 23 24 /** 25 * Name. 26 * @var Array of PEAR::DB 27 * @access private 28 */ 29 var $_dbs; 30 31 // {{{ _getDB() 32 33 /** 34 * method used to get an PEAR::DB depending on a dsn 35 * 36 * @return PEAR::DB 37 * @access public 38 */ 39 function &getDB ($dsn, $dbOptions) { 40 41 /* 42 return $this->_dbs[$dsn]; 43 */ 44 if (is_object($this->_dbs[$dsn])) { 45 return $this->_dbs[$dsn]; 46 } 47 else { 48 $this->_registerDBManager($dsn, $dbOptions); 49 } 50 51 return $this->_dbs[$dsn]; 52 } 53 54 // }}} 55 56 // {{{ DBManager constructor. 57 58 /** 59 * DBManager constructor. 60 * 61 * @access public 62 */ 63 function DBManager ($dsn, $dbOptions) { 64 $this->_dbs[$dsn] = $this->getDB($dsn, $dbOptions); 65 return $this->_dbs[$dsn]; 66 } 67 68 // }}} 69 70 // {{{ _registerDBManager 71 72 /** 73 * methode enregistrant un acces a une base de donnees 74 * 75 * @return DBManager object 76 * @access private 77 */ 78 function _registerDBManager ($dsn, $dbOptions) { 79 require_once("DB.php"); 80 $this->_dbs[$dsn] = &DB::connect($dsn, $dbOptions); 81 $obj = &$this->_dbs[$dsn]; 82 83 if (!DB::isError($obj)) { 84 $obj->setFetchMode(DB_FETCHMODE_ASSOC); 85 } 86 } 87 88 // }}} 89 90 // {{{ getDBManager 91 92 /** 93 * method used to get an singleton of DBManager instance 94 * 95 * @return Singleton of DBManager objec 96 * @access public 97 */ 98 function &getDBManager ($dsn, $dbOptions) { 99 static $singleton; 100 101 if (!isset($singleton[$dsn])) { 102 $singleton[$dsn] = new DBManager($dsn, $dbOptions); 103 } 104 105 return $singleton[$dsn]; 106 } 107 108 // }}} 109 } 110 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |