4 * @file CAS/PGTStorage/pgt-db.php
5 * Basic class for PGT database storage
10 * The PGTStorageDB class is a class for PGT database storage. An instance of
11 * this class is returned by CASClient::SetPGTStorageDB().
13 * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
15 * @ingroup internalPGTStorageDB
18 class PGTStorageDB extends PGTStorage
21 * @addtogroup internalPGTStorageDB
26 * a string representing a PEAR DB URL to connect to the database. Written by
27 * PGTStorageDB::PGTStorageDB(), read by getURL().
35 * This method returns the PEAR DB URL to use to connect to the database.
37 * @return a PEAR DB URL
47 * The handle of the connection to the database where PGT's are stored. Written by
48 * PGTStorageDB::init(), read by getLink().
56 * This method returns the handle of the connection to the database where PGT's are
59 * @return a handle of connection.
69 * The name of the table where PGT's are stored. Written by
70 * PGTStorageDB::PGTStorageDB(), read by getTable().
78 * This method returns the name of the table where PGT's are stored.
80 * @return the name of a table.
89 // ########################################################################
91 // ########################################################################
94 * This method returns an informational string giving the type of storage
95 * used by the object (used for debugging purposes).
97 * @return an informational string.
100 function getStorageType()
106 * This method returns an informational string giving informations on the
107 * parameters of the storage.(used for debugging purposes).
111 function getStorageInfo()
113 return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\'';
116 // ########################################################################
118 // ########################################################################
121 * The class constructor, called by CASClient::SetPGTStorageDB().
123 * @param $cas_parent the CASClient instance that creates the object.
124 * @param $user the user to access the data with
125 * @param $password the user's password
126 * @param $database_type the type of the database hosting the data
127 * @param $hostname the server hosting the database
128 * @param $port the port the server is listening on
129 * @param $database the name of the database
130 * @param $table the name of the table storing the data
134 function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table)
136 phpCAS::traceBegin();
138 // call the ancestor's constructor
139 $this->PGTStorage($cas_parent);
141 if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE;
142 if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME;
143 if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT;
144 if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE;
145 if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE;
147 // build and store the PEAR DB URL
148 $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database;
150 // XXX should use setURL and setTable
154 // ########################################################################
156 // ########################################################################
159 * This method is used to initialize the storage. Halts on error.
165 phpCAS::traceBegin();
166 // if the storage has already been initialized, return immediatly
167 if ( $this->isInitialized() )
169 // call the ancestor's method (mark as initialized)
172 //include phpDB library (the test was introduced in release 0.4.8 for
173 //the integration into Tikiwiki).
174 if (!class_exists('DB')) {
175 include_once('DB.php');
178 // try to connect to the database
179 $this->_link = DB::connect($this->getURL());
180 if ( DB::isError($this->_link) ) {
181 phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')');
183 var_dump($this->_link);