00001 <?php 00002 00008 // include phpDB library (the test was introduced in release 0.4.8 for 00009 // the integration into Tikiwiki). 00010 if (!class_exists('DB')) { 00011 include_once('DB.php'); 00012 } 00013 00024 class PGTStorageDB extends PGTStorage 00025 { 00038 var $_url=''; 00039 00047 function getURL() 00048 { 00049 return $this->_url; 00050 } 00051 00059 var $_link = null; 00060 00069 function getLink() 00070 { 00071 return $this->_link; 00072 } 00073 00081 var $_table = ''; 00082 00090 function getTable() 00091 { 00092 return $this->_table; 00093 } 00094 00095 // ######################################################################## 00096 // DEBUGGING 00097 // ######################################################################## 00098 00106 function getStorageType() 00107 { 00108 return "database"; 00109 } 00110 00117 function getStorageInfo() 00118 { 00119 return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\''; 00120 } 00121 00122 // ######################################################################## 00123 // CONSTRUCTOR 00124 // ######################################################################## 00125 00140 function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table) 00141 { 00142 phpCAS::traceBegin(); 00143 00144 // call the ancestor's constructor 00145 $this->PGTStorage($cas_parent); 00146 00147 if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; 00148 if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; 00149 if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; 00150 if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; 00151 if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; 00152 00153 // build and store the PEAR DB URL 00154 $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database; 00155 00156 // XXX should use setURL and setTable 00157 phpCAS::traceEnd(); 00158 } 00159 00160 // ######################################################################## 00161 // INITIALIZATION 00162 // ######################################################################## 00163 00169 function init() 00170 { 00171 phpCAS::traceBegin(); 00172 // if the storage has already been initialized, return immediatly 00173 if ( $this->isInitialized() ) 00174 return; 00175 // call the ancestor's method (mark as initialized) 00176 parent::init(); 00177 00178 // try to connect to the database 00179 $this->_link = DB::connect($this->getURL()); 00180 if ( DB::isError($this->_link) ) { 00181 phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')'); 00182 } 00183 var_dump($this->_link); 00184 phpCAS::traceBEnd(); 00185 } 00186 00188 } 00189 00190 ?>