ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

adodb-pear.inc.php
Go to the documentation of this file.
1 <?php
18  /*
19  We support:
20 
21  DB_Common
22  ---------
23  query - returns PEAR_Error on error
24  limitQuery - return PEAR_Error on error
25  prepare - does not return PEAR_Error on error
26  execute - does not return PEAR_Error on error
27  setFetchMode - supports ASSOC and ORDERED
28  errorNative
29  quote
30  nextID
31  disconnect
32 
33  getOne
34  getAssoc
35  getRow
36  getCol
37  getAll
38 
39  DB_Result
40  ---------
41  numRows - returns -1 if not supported
42  numCols
43  fetchInto - does not support passing of fetchmode
44  fetchRows - does not support passing of fetchmode
45  free
46  */
47 
48 define('ADODB_PEAR',dirname(__FILE__));
49 include_once "PEAR.php";
50 include_once ADODB_PEAR."/adodb-errorpear.inc.php";
51 include_once ADODB_PEAR."/adodb.inc.php";
52 
53 if (!defined('DB_OK')) {
54 define("DB_OK", 1);
55 define("DB_ERROR",-1);
56 
62 define('DB_FETCHMODE_DEFAULT', 0);
63 
68 define('DB_FETCHMODE_ORDERED', 1);
69 
74 define('DB_FETCHMODE_ASSOC', 2);
75 
76 /* for compatibility */
77 
78 define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
79 define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC);
80 
87 define('DB_TABLEINFO_ORDER', 1);
88 define('DB_TABLEINFO_ORDERTABLE', 2);
89 define('DB_TABLEINFO_FULL', 3);
90 }
91 
99 class DB
100 {
110  function factory($type)
111  {
112  include_once(ADODB_DIR."/drivers/adodb-$type.inc.php");
113  $obj = NewADOConnection($type);
114  if (!is_object($obj)) $obj = new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1);
115  return $obj;
116  }
117 
137  function connect($dsn, $options = false)
138  {
139  if (is_array($dsn)) {
140  $dsninfo = $dsn;
141  } else {
142  $dsninfo = DB::parseDSN($dsn);
143  }
144  switch ($dsninfo["phptype"]) {
145  case 'pgsql': $type = 'postgres7'; break;
146  case 'ifx': $type = 'informix9'; break;
147  default: $type = $dsninfo["phptype"]; break;
148  }
149 
150  if (is_array($options) && isset($options["debug"]) &&
151  $options["debug"] >= 2) {
152  // expose php errors with sufficient debug level
153  @include_once("adodb-$type.inc.php");
154  } else {
155  @include_once("adodb-$type.inc.php");
156  }
157 
158  @$obj = NewADOConnection($type);
159  if (!is_object($obj)) {
160  $obj = new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1);
161  return $obj;
162  }
163  if (is_array($options)) {
164  foreach($options as $k => $v) {
165  switch(strtolower($k)) {
166  case 'persist':
167  case 'persistent': $persist = $v; break;
168  #ibase
169  case 'dialect': $obj->dialect = $v; break;
170  case 'charset': $obj->charset = $v; break;
171  case 'buffers': $obj->buffers = $v; break;
172  #ado
173  case 'charpage': $obj->charPage = $v; break;
174  #mysql
175  case 'clientflags': $obj->clientFlags = $v; break;
176  }
177  }
178  } else {
179  $persist = false;
180  }
181 
182  if (isset($dsninfo['socket'])) $dsninfo['hostspec'] .= ':'.$dsninfo['socket'];
183  else if (isset($dsninfo['port'])) $dsninfo['hostspec'] .= ':'.$dsninfo['port'];
184 
185  if($persist) $ok = $obj->PConnect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']);
186  else $ok = $obj->Connect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']);
187 
188  if (!$ok) $obj = ADODB_PEAR_Error();
189  return $obj;
190  }
191 
197  function apiVersion()
198  {
199  return 2;
200  }
201 
209  function isError($value)
210  {
211  if (!is_object($value)) return false;
212  $class = strtolower(get_class($value));
213  return $class == 'pear_error' || is_subclass_of($value, 'pear_error') ||
214  $class == 'db_error' || is_subclass_of($value, 'db_error');
215  }
216 
217 
227  function isWarning($value)
228  {
229  return false;
230  /*
231  return is_object($value) &&
232  (get_class( $value ) == "db_warning" ||
233  is_subclass_of($value, "db_warning"));*/
234  }
235 
268  function parseDSN($dsn)
269  {
270  if (is_array($dsn)) {
271  return $dsn;
272  }
273 
274  $parsed = array(
275  'phptype' => false,
276  'dbsyntax' => false,
277  'protocol' => false,
278  'hostspec' => false,
279  'database' => false,
280  'username' => false,
281  'password' => false
282  );
283 
284  // Find phptype and dbsyntax
285  if (($pos = strpos($dsn, '://')) !== false) {
286  $str = substr($dsn, 0, $pos);
287  $dsn = substr($dsn, $pos + 3);
288  } else {
289  $str = $dsn;
290  $dsn = NULL;
291  }
292 
293  // Get phptype and dbsyntax
294  // $str => phptype(dbsyntax)
295  if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
296  $parsed['phptype'] = $arr[1];
297  $parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2];
298  } else {
299  $parsed['phptype'] = $str;
300  $parsed['dbsyntax'] = $str;
301  }
302 
303  if (empty($dsn)) {
304  return $parsed;
305  }
306 
307  // Get (if found): username and password
308  // $dsn => username:password@protocol+hostspec/database
309  if (($at = strpos($dsn,'@')) !== false) {
310  $str = substr($dsn, 0, $at);
311  $dsn = substr($dsn, $at + 1);
312  if (($pos = strpos($str, ':')) !== false) {
313  $parsed['username'] = urldecode(substr($str, 0, $pos));
314  $parsed['password'] = urldecode(substr($str, $pos + 1));
315  } else {
316  $parsed['username'] = urldecode($str);
317  }
318  }
319 
320  // Find protocol and hostspec
321  // $dsn => protocol+hostspec/database
322  if (($pos=strpos($dsn, '/')) !== false) {
323  $str = substr($dsn, 0, $pos);
324  $dsn = substr($dsn, $pos + 1);
325  } else {
326  $str = $dsn;
327  $dsn = NULL;
328  }
329 
330  // Get protocol + hostspec
331  // $str => protocol+hostspec
332  if (($pos=strpos($str, '+')) !== false) {
333  $parsed['protocol'] = substr($str, 0, $pos);
334  $parsed['hostspec'] = urldecode(substr($str, $pos + 1));
335  } else {
336  $parsed['hostspec'] = urldecode($str);
337  }
338 
339  // Get dabase if any
340  // $dsn => database
341  if (!empty($dsn)) {
342  $parsed['database'] = $dsn;
343  }
344 
345  return $parsed;
346  }
347 
359  function assertExtension($name)
360  {
361  if (!extension_loaded($name)) {
362  $dlext = (strncmp(PHP_OS,'WIN',3) === 0) ? '.dll' : '.so';
363  @dl($name . $dlext);
364  }
365  if (!extension_loaded($name)) {
366  return false;
367  }
368  return true;
369  }
370 }
ADODB_PEAR
const ADODB_PEAR
Definition: adodb-pear.inc.php:48
ADODB_PEAR_Error
ADODB_PEAR_Error()
Definition: adodb-errorpear.inc.php:83
DB\factory
factory($type)
Definition: adodb-pear.inc.php:110
$type
$type
Definition: dcm.php:17
DB\assertExtension
assertExtension($name)
Definition: adodb-pear.inc.php:359
DB\apiVersion
apiVersion()
Definition: adodb-pear.inc.php:197
DB\isWarning
isWarning($value)
Definition: adodb-pear.inc.php:227
DB\connect
connect($dsn, $options=false)
Definition: adodb-pear.inc.php:137
DB\isError
isError($value)
Definition: adodb-pear.inc.php:209
DB
Definition: adodb-pear.inc.php:99
DB\parseDSN
parseDSN($dsn)
Definition: adodb-pear.inc.php:268