ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
pgt-db.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright © 2003-2010, The ESUP-Portail consortium & the JA-SIG Collaborative.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * * Neither the name of the ESUP-Portail consortium & the JA-SIG
15 * Collaborative nor the names of its contributors may be used to endorse or
16 * promote products derived from this software without specific prior
17 * written permission.
18
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
47{
60 var $_url='';
61
69 function getURL()
70 {
71 return $this->_url;
72 }
73
81 var $_link = null;
82
91 function getLink()
92 {
93 return $this->_link;
94 }
95
103 var $_table = '';
104
112 function getTable()
113 {
114 return $this->_table;
115 }
116
117 // ########################################################################
118 // DEBUGGING
119 // ########################################################################
120
128 function getStorageType()
129 {
130 return "database";
131 }
132
139 function getStorageInfo()
140 {
141 return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\'';
142 }
143
144 // ########################################################################
145 // CONSTRUCTOR
146 // ########################################################################
147
162 function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table)
163 {
165
166 // call the ancestor's constructor
167 $this->PGTStorage($cas_parent);
168
169 if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE;
170 if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME;
171 if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT;
172 if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE;
173 if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE;
174
175 // build and store the PEAR DB URL
176 $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database;
177
178 // XXX should use setURL and setTable
180 }
181
182 // ########################################################################
183 // INITIALIZATION
184 // ########################################################################
185
191 function init()
192 {
194 // if the storage has already been initialized, return immediatly
195 if ( $this->isInitialized() )
196 return;
197 // call the ancestor's method (mark as initialized)
198 parent::init();
199
200 //include phpDB library (the test was introduced in release 0.4.8 for
201 //the integration into Tikiwiki).
202 if (!class_exists('DB')) {
203 include_once('DB.php');
204 }
205
206 // try to connect to the database
207 $this->_link = DB::connect($this->getURL());
208 if ( DB::isError($this->_link) ) {
209 phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')');
210 }
211 var_dump($this->_link);
212 phpCAS::traceBEnd();
213 }
214
216}
217
218?>
The PGTStorageDB class is a class for PGT database storage.
Definition: pgt-db.php:47
The PGTStorage class is a generic class for PGT storage.
Definition: pgt-main.php:46
error($msg)
This method is used by interface methods to print an error and where the function was originally call...
Definition: CAS.php:544
traceBegin()
This method is used to indicate the start of the execution of a function in debug mode.
Definition: CAS.php:577
traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:604
getStorageInfo()
This method returns an informational string giving informations on the parameters of the storage.
Definition: pgt-db.php:139
getTable()
This method returns the name of the table where PGT's are stored.
Definition: pgt-db.php:112
$_url
a string representing a PEAR DB URL to connect to the database.
Definition: pgt-db.php:60
init()
This method is used to initialize the storage.
Definition: pgt-db.php:191
$_link
The handle of the connection to the database where PGT's are stored.
Definition: pgt-db.php:81
getURL()
This method returns the PEAR DB URL to use to connect to the database.
Definition: pgt-db.php:69
getStorageType()
This method returns an informational string giving the type of storage used by the object (used for d...
Definition: pgt-db.php:128
PGTStorageDB($cas_parent, $user, $password, $database_type, $hostname, $port, $database, $table)
The class constructor, called by CASClient::SetPGTStorageDB().
Definition: pgt-db.php:162
$_table
The name of the table where PGT's are stored.
Definition: pgt-db.php:103
getLink()
This method returns the handle of the connection to the database where PGT's are stored.
Definition: pgt-db.php:91
isInitialized()
This method tells if the storage has already been intialized.
Definition: pgt-main.php:160
PGTStorage($cas_parent)
The constructor of the class, should be called only by inherited classes.
Definition: pgt-main.php:63
const CAS_PGT_STORAGE_DB_DEFAULT_TABLE
default table when storing PGT's to database
Definition: CAS.php:184
const CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE
default database type when storing PGT's to database
Definition: CAS.php:168
const CAS_PGT_STORAGE_DB_DEFAULT_DATABASE
default database when storing PGT's to database
Definition: CAS.php:180
const CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME
default host when storing PGT's to database
Definition: CAS.php:172
const CAS_PGT_STORAGE_DB_DEFAULT_PORT
default port when storing PGT's to database
Definition: CAS.php:176