[ 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 // $Id$ 20 21 require_once dirname(__FILE__). "/metier.php"; 22 23 if (file_exists(dirname(__FILE__). "/inc_config_metier.php")) { 24 require_once dirname(__FILE__). "/inc_config_metier.php"; 25 } 26 27 /** 28 * BD_metier is a base class for all business persistence abstraction implementations, and must be 29 * inherited by all such. 30 * @package BD 31 * @author Antoine Angénieux <aangenieux@clever-age.com> 32 * @author Erwan Le Bescond <elebescond@clever-age.com> 33 * @author Olivier Mansour <omansour@clever-age.com> 34 * @access public 35 */ 36 37 class BD_connexion extends BD_metier { 38 // {{{ properties 39 40 /** 41 * Parameters instance used for PEAR::DB factory and 42 * Metier subclasses factories. 43 * 44 * @access private 45 */ 46 var $_dbParameters; 47 48 // }}} 49 50 // {{{ factory() 51 function &factory ($dbParameters = null, $dbOptions = null) { 52 if (file_exists( 53 dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/connexion_" . $dbParameters->_dbEngine . ".php") 54 == false) { 55 include_once(dirname(__FILE__). "/common/connexion_common.php"); 56 $classname = "BD_connexion_common"; 57 } 58 else { 59 include_once( 60 dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/connexion_" . $dbParameters->_dbEngine . ".php"); 61 $classname = "BD_connexion_" . $dbParameters->_dbEngine; 62 } 63 64 if (!class_exists($classname)) { 65 return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false); 66 } 67 68 //echo "$classname"; 69 $obj = &new $classname; 70 $result = $obj->setDbParameters($dbParameters); 71 72 if ($dbOptions != null) { 73 $obj->setDbOptions($dbOptions); 74 } 75 /* 76 if (PEAR::isError($result)) { 77 return $result; 78 } else { 79 return $obj; 80 } 81 */ 82 return $obj; 83 } 84 85 // }}} 86 87 // {{{ isConnected() 88 89 function isConnected () { 90 /* 91 require_once dirname(__FILE__)."/inc_metier_factory.php"; 92 $metier = &recuperer_instance_metier(); 93 94 $db = $metier->_getDB(); 95 */ 96 $db = $this->_getDB(); 97 98 if (DB::isError($db)) { 99 //return PEAR::raiseError("[".get_class($this)." DB_connexion : isConnected()] ".$db->getMessage()."", null, 100 // null, null, null, null, false); 101 return false; 102 } 103 104 // TODO : pas plus rapide pour tester la connection et l'installation de SPIP Agora ? 105 $query = "SELECT COUNT(nom) as compteur FROM " . $GLOBALS['table_prefix']. "_meta"; 106 /* 107 echo $query; 108 */ 109 110 $result = $db->query($query); 111 112 if (DB::isError($result)) { 113 //return PEAR::raiseError("[".get_class($this)." DB_connexion : isConnected()] ".$result->getMessage()."", null, 114 // null, null, null, null, false); 115 return false; 116 } 117 else { 118 if ($row = $result->fetchRow()) { 119 //return $row['compteur']; 120 return true; 121 } 122 else { 123 return false; 124 } 125 } 126 } 127 // }}} 128 129 /** 130 * Getter method to retreive the instance Parameters object 131 * 132 * @return DB parameters 133 * @access public 134 */ 135 136 function getDbParameters () { 137 return $this->_dbParameters; 138 } 139 140 // }}} 141 142 // {{{ setDbParameters() 143 144 /** 145 * Setter method to set the instance Parameters object 146 * 147 * @param $dbParameters new DB parameters 148 */ 149 150 function setDbParameters ($dbParameters) { 151 if (strtolower(get_class($dbParameters)) == "bd_parameters") { 152 $this->_dbParameters = $dbParameters; 153 } 154 else { 155 // return PEAR::raiseError("Erreur! le parametre de la methode setDbParameters doit etre un objet de la hierarchie DB_parameters !", 156 // null, null, null, null, null, false); 157 die("Erreur! le parametre de la methode setDbParameters doit etre un objet de la hierarchie DB_parameters !"); // en attendant mieux; 158 } 159 } 160 161 // }}} 162 163 } 164 ?>
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 |