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