ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
pgt-db.php
Go to the documentation of this file.
1 <?php
2 
8 // include phpDB library (the test was introduced in release 0.4.8 for
9 // the integration into Tikiwiki).
10 if (!class_exists('DB')) {
11  include_once('DB.php');
12 }
13 
24 class PGTStorageDB extends PGTStorage
25 {
38  var $_url='';
39 
47  function getURL()
48  {
49  return $this->_url;
50  }
51 
59  var $_link = null;
60 
69  function getLink()
70  {
71  return $this->_link;
72  }
73 
81  var $_table = '';
82 
90  function getTable()
91  {
92  return $this->_table;
93  }
94 
95  // ########################################################################
96  // DEBUGGING
97  // ########################################################################
98 
106  function getStorageType()
107  {
108  return "database";
109  }
110 
117  function getStorageInfo()
118  {
119  return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\'';
120  }
121 
122  // ########################################################################
123  // CONSTRUCTOR
124  // ########################################################################
125 
140  function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table)
141  {
143 
144  // call the ancestor's constructor
145  $this->PGTStorage($cas_parent);
146 
147  if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE;
148  if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME;
149  if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT;
150  if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE;
151  if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE;
152 
153  // build and store the PEAR DB URL
154  $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$server.':'.$port.'/'.$database;
155 
156  // XXX should use setURL and setTable
158  }
159 
160  // ########################################################################
161  // INITIALIZATION
162  // ########################################################################
163 
169  function init()
170  {
172  // if the storage has already been initialized, return immediatly
173  if ( $this->isInitialized() )
174  return;
175  // call the ancestor's method (mark as initialized)
176  parent::init();
177 
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).')');
182  }
183  var_dump($this->_link);
184  phpCAS::traceBEnd();
185  }
186 
188 }
189 
190 ?>