00001 <?php 00002 /* 00003 * Copyright © 2003-2010, The ESUP-Portail consortium & the JA-SIG Collaborative. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * * Redistributions of source code must retain the above copyright notice, 00010 * this list of conditions and the following disclaimer. 00011 * * Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * * Neither the name of the ESUP-Portail consortium & the JA-SIG 00015 * Collaborative nor the names of its contributors may be used to endorse or 00016 * promote products derived from this software without specific prior 00017 * written permission. 00018 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00046 class PGTStorageDB extends PGTStorage 00047 { 00060 var $_url=''; 00061 00069 function getURL() 00070 { 00071 return $this->_url; 00072 } 00073 00081 var $_link = null; 00082 00091 function getLink() 00092 { 00093 return $this->_link; 00094 } 00095 00103 var $_table = ''; 00104 00112 function getTable() 00113 { 00114 return $this->_table; 00115 } 00116 00117 // ######################################################################## 00118 // DEBUGGING 00119 // ######################################################################## 00120 00128 function getStorageType() 00129 { 00130 return "database"; 00131 } 00132 00139 function getStorageInfo() 00140 { 00141 return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\''; 00142 } 00143 00144 // ######################################################################## 00145 // CONSTRUCTOR 00146 // ######################################################################## 00147 00162 function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table) 00163 { 00164 phpCAS::traceBegin(); 00165 00166 // call the ancestor's constructor 00167 $this->PGTStorage($cas_parent); 00168 00169 if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; 00170 if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; 00171 if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; 00172 if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; 00173 if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; 00174 00175 // build and store the PEAR DB URL 00176 $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database; 00177 00178 // XXX should use setURL and setTable 00179 phpCAS::traceEnd(); 00180 } 00181 00182 // ######################################################################## 00183 // INITIALIZATION 00184 // ######################################################################## 00185 00191 function init() 00192 { 00193 phpCAS::traceBegin(); 00194 // if the storage has already been initialized, return immediatly 00195 if ( $this->isInitialized() ) 00196 return; 00197 // call the ancestor's method (mark as initialized) 00198 parent::init(); 00199 00200 //include phpDB library (the test was introduced in release 0.4.8 for 00201 //the integration into Tikiwiki). 00202 if (!class_exists('DB')) { 00203 include_once('DB.php'); 00204 } 00205 00206 // try to connect to the database 00207 $this->_link = DB::connect($this->getURL()); 00208 if ( DB::isError($this->_link) ) { 00209 phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')'); 00210 } 00211 var_dump($this->_link); 00212 phpCAS::traceBEnd(); 00213 } 00214 00216 } 00217 00218 ?>