ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

DBConnection.inc.php
Go to the documentation of this file.
1 <?php
2 
16 // $Id$
17 
18 
19 class DBConnection {
20 
22  var $dbconn;
23 
25  var $driver;
26  var $host;
27  var $username;
28  var $password;
32  var $forceNew; // Only applicable if non-persistent
33 
36 
37  /* @var boolean enable debugging output */
38  var $debug;
39 
42 
49  function DBConnection() {
50  $this->connected = false;
51 
52  if (func_num_args() == 0) {
53  $this->initDefaultDBConnection();
54  } else {
55  $args = func_get_args();
56  call_user_func_array(array(&$this, 'initCustomDBConnection'), $args);
57  }
58  }
59 
66  $this->driver = Config::getVar('database', 'driver');
67  $this->host = Config::getVar('database', 'host');
68  $this->username = Config::getVar('database', 'username');
69  $this->password = Config::getVar('database', 'password');
70  $this->databaseName = Config::getVar('database', 'name');
71  $this->persistent = Config::getVar('database', 'persistent') ? true : false;
72  $this->connectionCharset = Config::getVar('i18n', 'connection_charset');
73  $this->debug = Config::getVar('database', 'debug') ? true : false;
74  $this->connectOnInit = true;
75  $this->forceNew = false;
76 
77  return $this->initConn();
78  }
79 
96  $this->driver = $driver;
97  $this->host = $host;
98  $this->username = $username;
99  $this->password = $password;
100  $this->databaseName = $databaseName;
101  $this->persistent = $persistent;
102  $this->connectionCharset = $connectionCharset;
103  $this->connectOnInit = $connectOnInit;
104  $this->debug = $debug;
105  $this->forceNew = $forceNew;
106 
107  return $this->initConn();
108  }
109 
114  function initConn() {
115  require_once('adodb.inc.php');
116 
117  $this->dbconn =& ADONewConnection($this->driver);
118 
119  if ($this->connectOnInit) {
120  return $this->connect();
121  } else {
122  return true;
123  }
124  }
125 
130  function connect() {
131  if ($this->persistent) {
132  $this->connected = @$this->dbconn->PConnect(
133  $this->host,
134  $this->username,
135  $this->password,
136  $this->databaseName
137  );
138 
139  } else {
140  $this->connected = @$this->dbconn->Connect(
141  $this->host,
142  $this->username,
143  $this->password,
144  $this->databaseName,
145  $this->forceNew
146  );
147  }
148 
149  if ($this->debug) {
150  // Enable verbose database debugging (prints all SQL statements as they're executed)
151  $this->dbconn->debug = true;
152  }
153 
154  if ($this->connected && $this->connectionCharset) {
155  // Set client/connection character set
156  // NOTE: Only supported on some database servers and versions
157  $this->dbconn->SetCharSet($this->connectionCharset);
158  }
159 
160  return $this->connected;
161  }
162 
166  function disconnect() {
167  if ($this->connected) {
168  $this->dbconn->Disconnect();
169  $this->connected = false;
170  }
171  }
172 
177  function reconnect($forceNew = false) {
178  $this->disconnect();
179  if ($forceNew) {
180  $this->persistent = false;
181  }
182  $this->forceNew = $forceNew;
183  return $this->connect();
184  }
185 
190  function &getDBConn() {
191  return $this->dbconn;
192  }
193 
198  function isConnected() {
199  return $this->connected;
200  }
201 
206  function getNumQueries() {
207  return isset($this->dbconn) ? $this->dbconn->numQueries : 0;
208  }
209 
215  function &getInstance($setInstance = null) {
216  $instance =& Registry::get('dbInstance', true, null);
217 
218  if (isset($setInstance)) {
219  $instance = $setInstance;
220  } else if ($instance === null) {
221  $instance = new DBConnection();
222  }
223 
224  return $instance;
225  }
226 
231  function &getConn() {
232  $conn =& DBConnection::getInstance();
233  return $conn->getDBConn();
234  }
235 
240  function getDriver() {
241  return $this->driver;
242  }
243 
249  function logQuery($sql, $start, $params = array()) {
250  if (!Config::getVar('debug', 'show_stats')) return;
251 
252  $queries =& Registry::get('queries', true, array());
253 
254  // re-combine the SQL into a prepared statement
255  $preparedSql = '';
256  foreach(explode('?',$sql) as $key => $val) {
257  if (isset($params[$key])) {
258  $preparedSql .= $val.$params[$key];
259  }
260  }
261 
262  $query = array(
263  'sql' => $preparedSql,
264  'time' => (Core::microtime() - $start)*1000
265  );
266  array_push($queries, $query);
267  }
268 }
269 
270 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
initCustomDBConnection($driver, $host, $username, $password, $databaseName, $persistent=true, $connectionCharset=false, $connectOnInit=true, $debug=false, $forceNew=false)
reconnect($forceNew=false)
microtime()
Definition: Core.inc.php:98
& getInstance($setInstance=null)
getVar($section, $key, $default=null)
Definition: Config.inc.php:35
driver
Definition: config.inc.php:96
logQuery($sql, $start, $params=array())
& get($key, $createIfEmpty=false, $createWithDefault=null)
Class for accessing the low-level database connection. Currently integrated with ADOdb (from http://a...