3 * Copyright © 2003-2010, The ESUP-Portail consortium & the JA-SIG Collaborative.
\r
4 * All rights reserved.
\r
6 * Redistribution and use in source and binary forms, with or without
\r
7 * modification, are permitted provided that the following conditions are met:
\r
9 * * Redistributions of source code must retain the above copyright notice,
\r
10 * this list of conditions and the following disclaimer.
\r
11 * * Redistributions in binary form must reproduce the above copyright notice,
\r
12 * this list of conditions and the following disclaimer in the documentation
\r
13 * and/or other materials provided with the distribution.
\r
14 * * Neither the name of the ESUP-Portail consortium & the JA-SIG
\r
15 * Collaborative nor the names of its contributors may be used to endorse or
\r
16 * promote products derived from this software without specific prior
\r
17 * written permission.
\r
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
\r
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
\r
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
\r
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 * @file CAS/PGTStorage/pgt-db.php
\r
33 * Basic class for PGT database storage
\r
37 * @class PGTStorageDB
\r
38 * The PGTStorageDB class is a class for PGT database storage. An instance of
\r
39 * this class is returned by CASClient::SetPGTStorageDB().
\r
41 * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
\r
43 * @ingroup internalPGTStorageDB
\r
46 class PGTStorageDB extends PGTStorage
\r
49 * @addtogroup internalPGTStorageDB
\r
54 * a string representing a PEAR DB URL to connect to the database. Written by
\r
55 * PGTStorageDB::PGTStorageDB(), read by getURL().
\r
63 * This method returns the PEAR DB URL to use to connect to the database.
\r
65 * @return a PEAR DB URL
\r
75 * The handle of the connection to the database where PGT's are stored. Written by
\r
76 * PGTStorageDB::init(), read by getLink().
\r
84 * This method returns the handle of the connection to the database where PGT's are
\r
87 * @return a handle of connection.
\r
93 return $this->_link;
\r
97 * The name of the table where PGT's are stored. Written by
\r
98 * PGTStorageDB::PGTStorageDB(), read by getTable().
\r
106 * This method returns the name of the table where PGT's are stored.
\r
108 * @return the name of a table.
\r
112 function getTable()
\r
114 return $this->_table;
\r
117 // ########################################################################
\r
119 // ########################################################################
\r
122 * This method returns an informational string giving the type of storage
\r
123 * used by the object (used for debugging purposes).
\r
125 * @return an informational string.
\r
128 function getStorageType()
\r
134 * This method returns an informational string giving informations on the
\r
135 * parameters of the storage.(used for debugging purposes).
\r
139 function getStorageInfo()
\r
141 return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\'';
\r
144 // ########################################################################
\r
146 // ########################################################################
\r
149 * The class constructor, called by CASClient::SetPGTStorageDB().
\r
151 * @param $cas_parent the CASClient instance that creates the object.
\r
152 * @param $user the user to access the data with
\r
153 * @param $password the user's password
\r
154 * @param $database_type the type of the database hosting the data
\r
155 * @param $hostname the server hosting the database
\r
156 * @param $port the port the server is listening on
\r
157 * @param $database the name of the database
\r
158 * @param $table the name of the table storing the data
\r
162 function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table)
\r
164 phpCAS::traceBegin();
\r
166 // call the ancestor's constructor
\r
167 $this->PGTStorage($cas_parent);
\r
169 if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE;
\r
170 if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME;
\r
171 if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT;
\r
172 if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE;
\r
173 if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE;
\r
175 // build and store the PEAR DB URL
\r
176 $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database;
\r
178 // XXX should use setURL and setTable
\r
179 phpCAS::traceEnd();
\r
182 // ########################################################################
\r
184 // ########################################################################
\r
187 * This method is used to initialize the storage. Halts on error.
\r
193 phpCAS::traceBegin();
\r
194 // if the storage has already been initialized, return immediatly
\r
195 if ( $this->isInitialized() )
\r
197 // call the ancestor's method (mark as initialized)
\r
200 //include phpDB library (the test was introduced in release 0.4.8 for
\r
201 //the integration into Tikiwiki).
\r
202 if (!class_exists('DB')) {
\r
203 include_once('DB.php');
\r
206 // try to connect to the database
\r
207 $this->_link = DB::connect($this->getURL());
\r
208 if ( DB::isError($this->_link) ) {
\r
209 phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')');
\r
211 var_dump($this->_link);
\r
212 phpCAS::traceBEnd();
\r