ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
MDB2.php
Go to the documentation of this file.
1 <?php
2 // vim: set et ts=4 sw=4 fdm=marker:
3 // +----------------------------------------------------------------------+
4 // | PHP versions 4 and 5 |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
7 // | Stig. S. Bakken, Lukas Smith |
8 // | All rights reserved. |
9 // +----------------------------------------------------------------------+
10 // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
11 // | API as well as database abstraction for PHP applications. |
12 // | This LICENSE is in the BSD license style. |
13 // | |
14 // | Redistribution and use in source and binary forms, with or without |
15 // | modification, are permitted provided that the following conditions |
16 // | are met: |
17 // | |
18 // | Redistributions of source code must retain the above copyright |
19 // | notice, this list of conditions and the following disclaimer. |
20 // | |
21 // | Redistributions in binary form must reproduce the above copyright |
22 // | notice, this list of conditions and the following disclaimer in the |
23 // | documentation and/or other materials provided with the distribution. |
24 // | |
25 // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
26 // | Lukas Smith nor the names of his contributors may be used to endorse |
27 // | or promote products derived from this software without specific prior|
28 // | written permission. |
29 // | |
30 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
31 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
32 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
33 // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
34 // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
35 // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
36 // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
37 // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
38 // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
39 // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
40 // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
41 // | POSSIBILITY OF SUCH DAMAGE. |
42 // +----------------------------------------------------------------------+
43 // | Author: Lukas Smith <smith@pooteeweet.org> |
44 // +----------------------------------------------------------------------+
45 //
46 // $Id: MDB2.php,v 1.292 2007/04/25 09:31:01 quipo Exp $
47 //
48 
55 // PATCH
56 set_include_path("./Services/Database/lib/PEAR" . PATH_SEPARATOR . ini_get('include_path'));
57 if (!class_exists('PEAR')) {
58  require_once 'PEAR.php';
59 }
60 // END PATCH
61 
62 // {{{ Error constants
63 
72 define('MDB2_OK', true);
73 define('MDB2_ERROR', -1);
74 define('MDB2_ERROR_SYNTAX', -2);
75 define('MDB2_ERROR_CONSTRAINT', -3);
76 define('MDB2_ERROR_NOT_FOUND', -4);
77 define('MDB2_ERROR_ALREADY_EXISTS', -5);
78 define('MDB2_ERROR_UNSUPPORTED', -6);
79 define('MDB2_ERROR_MISMATCH', -7);
80 define('MDB2_ERROR_INVALID', -8);
81 define('MDB2_ERROR_NOT_CAPABLE', -9);
82 define('MDB2_ERROR_TRUNCATED', -10);
83 define('MDB2_ERROR_INVALID_NUMBER', -11);
84 define('MDB2_ERROR_INVALID_DATE', -12);
85 define('MDB2_ERROR_DIVZERO', -13);
86 define('MDB2_ERROR_NODBSELECTED', -14);
87 define('MDB2_ERROR_CANNOT_CREATE', -15);
88 define('MDB2_ERROR_CANNOT_DELETE', -16);
89 define('MDB2_ERROR_CANNOT_DROP', -17);
90 define('MDB2_ERROR_NOSUCHTABLE', -18);
91 define('MDB2_ERROR_NOSUCHFIELD', -19);
92 define('MDB2_ERROR_NEED_MORE_DATA', -20);
93 define('MDB2_ERROR_NOT_LOCKED', -21);
94 define('MDB2_ERROR_VALUE_COUNT_ON_ROW', -22);
95 define('MDB2_ERROR_INVALID_DSN', -23);
96 define('MDB2_ERROR_CONNECT_FAILED', -24);
97 define('MDB2_ERROR_EXTENSION_NOT_FOUND',-25);
98 define('MDB2_ERROR_NOSUCHDB', -26);
99 define('MDB2_ERROR_ACCESS_VIOLATION', -27);
100 define('MDB2_ERROR_CANNOT_REPLACE', -28);
101 define('MDB2_ERROR_CONSTRAINT_NOT_NULL',-29);
102 define('MDB2_ERROR_DEADLOCK', -30);
103 define('MDB2_ERROR_CANNOT_ALTER', -31);
104 define('MDB2_ERROR_MANAGER', -32);
105 define('MDB2_ERROR_MANAGER_PARSE', -33);
106 define('MDB2_ERROR_LOADMODULE', -34);
107 define('MDB2_ERROR_INSUFFICIENT_DATA', -35);
108 // }}}
109 // {{{ Verbose constants
114 define('MDB2_PREPARE_MANIP', false);
115 define('MDB2_PREPARE_RESULT', null);
116 
117 // }}}
118 // {{{ Fetchmode constants
119 
124 define('MDB2_FETCHMODE_DEFAULT', 0);
125 
129 define('MDB2_FETCHMODE_ORDERED', 1);
130 
134 define('MDB2_FETCHMODE_ASSOC', 2);
135 
139 define('MDB2_FETCHMODE_OBJECT', 3);
140 
147 define('MDB2_FETCHMODE_FLIPPED', 4);
148 
149 // }}}
150 // {{{ Portability mode constants
151 
156 define('MDB2_PORTABILITY_NONE', 0);
157 
163 define('MDB2_PORTABILITY_FIX_CASE', 1);
164 
169 define('MDB2_PORTABILITY_RTRIM', 2);
170 
175 define('MDB2_PORTABILITY_DELETE_COUNT', 4);
176 
181 define('MDB2_PORTABILITY_NUMROWS', 8);
182 
196 define('MDB2_PORTABILITY_ERRORS', 16);
197 
203 define('MDB2_PORTABILITY_EMPTY_TO_NULL', 32);
204 
209 define('MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES', 64);
210 
215 define('MDB2_PORTABILITY_ALL', 127);
216 
217 // }}}
218 // {{{ Globals for class instance tracking
219 
224 $GLOBALS['_MDB2_databases'] = array();
225 $GLOBALS['_MDB2_dsninfo_default'] = array(
226  'phptype' => false,
227  'dbsyntax' => false,
228  'username' => false,
229  'password' => false,
230  'protocol' => false,
231  'hostspec' => false,
232  'port' => false,
233  'socket' => false,
234  'database' => false,
235  'mode' => false,
236 );
237 
238 // }}}
239 // {{{ class MDB2
240 
270 class MDB2
271 {
272  // {{{ function setOptions(&$db, $options)
273 
284  function setOptions(&$db, $options)
285  {
286  if (is_array($options)) {
287  foreach ($options as $option => $value) {
288  $test = $db->setOption($option, $value);
289  if (PEAR::isError($test)) {
290  return $test;
291  }
292  }
293  }
294  return MDB2_OK;
295  }
296 
297  // }}}
298  // {{{ function classExists($classname)
299 
309  function classExists($classname)
310  {
311  if (version_compare(phpversion(), "5.0", ">=")) {
312  return class_exists($classname, false);
313  }
314  return class_exists($classname);
315  }
316 
317  // }}}
318  // {{{ function loadClass($class_name, $debug)
319 
330  function loadClass($class_name, $debug)
331  {
332  if (!MDB2::classExists($class_name)) {
333  $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php';
334  if ($debug) {
335  $include = include_once($file_name);
336  } else {
337  $include = @include_once($file_name);
338  }
339  if (!$include) {
340  if (!MDB2::fileExists($file_name)) {
341  $msg = "unable to find package '$class_name' file '$file_name'";
342  } else {
343  $msg = "unable to load class '$class_name' from file '$file_name'";
344  }
345  $err =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg);
346  return $err;
347  }
348  }
349  return MDB2_OK;
350  }
351 
352  // }}}
353  // {{{ function &factory($dsn, $options = false)
354 
379  function &factory($dsn, $options = false)
380  {
381  $dsninfo = MDB2::parseDSN($dsn);
382  if (empty($dsninfo['phptype'])) {
384  null, null, 'no RDBMS driver specified');
385  return $err;
386  }
387  $class_name = 'MDB2_Driver_'.$dsninfo['phptype'];
388 
389  $debug = (!empty($options['debug']));
390  $err = MDB2::loadClass($class_name, $debug);
391  if (PEAR::isError($err)) {
392  return $err;
393  }
394 
395  $db = new $class_name();
396  $db->setDSN($dsninfo);
397  $err = MDB2::setOptions($db, $options);
398  if (PEAR::isError($err)) {
399  return $err;
400  }
401 
402  return $db;
403  }
404 
405  // }}}
406  // {{{ function &connect($dsn, $options = false)
407 
436  function &connect($dsn, $options = false)
437  {
438  $db =& MDB2::factory($dsn, $options);
439  if (PEAR::isError($db)) {
440  return $db;
441  }
442 
443  $err = $db->connect();
444  if (PEAR::isError($err)) {
445  $dsn = $db->getDSN('string', 'xxx');
446  $db->disconnect();
447  $err->addUserInfo($dsn);
448  return $err;
449  }
450 
451  return $db;
452  }
453 
454  // }}}
455  // {{{ function &singleton($dsn = null, $options = false)
456 
486  function &singleton($dsn = null, $options = false)
487  {
488  if ($dsn) {
489  $dsninfo = MDB2::parseDSN($dsn);
490  $dsninfo = array_merge($GLOBALS['_MDB2_dsninfo_default'], $dsninfo);
491  $keys = array_keys($GLOBALS['_MDB2_databases']);
492  for ($i=0, $j=count($keys); $i<$j; ++$i) {
493  if (isset($GLOBALS['_MDB2_databases'][$keys[$i]])) {
494  $tmp_dsn = $GLOBALS['_MDB2_databases'][$keys[$i]]->getDSN('array');
495  if (count(array_diff_assoc($tmp_dsn, $dsninfo)) == 0) {
496  MDB2::setOptions($GLOBALS['_MDB2_databases'][$keys[$i]], $options);
497  return $GLOBALS['_MDB2_databases'][$keys[$i]];
498  }
499  }
500  }
501  } elseif (is_array($GLOBALS['_MDB2_databases']) && reset($GLOBALS['_MDB2_databases'])) {
502  $db =& $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])];
503  return $db;
504  }
505  $db =& MDB2::factory($dsn, $options);
506  return $db;
507  }
508 
509  // }}}
510  // {{{ function loadFile($file)
511 
521  function loadFile($file)
522  {
523  $file_name = 'MDB2'.DIRECTORY_SEPARATOR.$file.'.php';
524  if (!MDB2::fileExists($file_name)) {
525  return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
526  'unable to find: '.$file_name);
527  }
528  if (!include_once($file_name)) {
529  return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
530  'unable to load driver class: '.$file_name);
531  }
532  return $file_name;
533  }
534 
535  // }}}
536  // {{{ function apiVersion()
537 
545  function apiVersion()
546  {
547  return '2.4.1';
548  }
549 
550  // }}}
551  // {{{ function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
552 
577  function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
578  {
579  $err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
580  return $err;
581  }
582 
583  // }}}
584  // {{{ function isError($data, $code = null)
585 
599  function isError($data, $code = null)
600  {
601  if (is_a($data, 'MDB2_Error')) {
602  if (is_null($code)) {
603  return true;
604  } elseif (is_string($code)) {
605  return $data->getMessage() === $code;
606  } else {
607  $code = (array)$code;
608  return in_array($data->getCode(), $code);
609  }
610  }
611  return false;
612  }
613 
614  // }}}
615  // {{{ function isConnection($value)
616 
626  function isConnection($value)
627  {
628  return is_a($value, 'MDB2_Driver_Common');
629  }
630 
631  // }}}
632  // {{{ function isResult($value)
633 
643  function isResult($value)
644  {
645  return is_a($value, 'MDB2_Result');
646  }
647 
648  // }}}
649  // {{{ function isResultCommon($value)
650 
660  function isResultCommon($value)
661  {
662  return is_a($value, 'MDB2_Result_Common');
663  }
664 
665  // }}}
666  // {{{ function isStatement($value)
667 
677  function isStatement($value)
678  {
679  return is_a($value, 'MDB2_Statement');
680  }
681 
682  // }}}
683  // {{{ function errorMessage($value = null)
684 
697  function errorMessage($value = null)
698  {
699  static $errorMessages;
700 
701  if (is_array($value)) {
702  $errorMessages = $value;
703  return MDB2_OK;
704  }
705 
706  if (!isset($errorMessages)) {
707  $errorMessages = array(
708  MDB2_OK => 'no error',
709  MDB2_ERROR => 'unknown error',
710  MDB2_ERROR_ALREADY_EXISTS => 'already exists',
711  MDB2_ERROR_CANNOT_CREATE => 'can not create',
712  MDB2_ERROR_CANNOT_ALTER => 'can not alter',
713  MDB2_ERROR_CANNOT_REPLACE => 'can not replace',
714  MDB2_ERROR_CANNOT_DELETE => 'can not delete',
715  MDB2_ERROR_CANNOT_DROP => 'can not drop',
716  MDB2_ERROR_CONSTRAINT => 'constraint violation',
717  MDB2_ERROR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
718  MDB2_ERROR_DIVZERO => 'division by zero',
719  MDB2_ERROR_INVALID => 'invalid',
720  MDB2_ERROR_INVALID_DATE => 'invalid date or time',
721  MDB2_ERROR_INVALID_NUMBER => 'invalid number',
722  MDB2_ERROR_MISMATCH => 'mismatch',
723  MDB2_ERROR_NODBSELECTED => 'no database selected',
724  MDB2_ERROR_NOSUCHFIELD => 'no such field',
725  MDB2_ERROR_NOSUCHTABLE => 'no such table',
726  MDB2_ERROR_NOT_CAPABLE => 'MDB2 backend not capable',
727  MDB2_ERROR_NOT_FOUND => 'not found',
728  MDB2_ERROR_NOT_LOCKED => 'not locked',
729  MDB2_ERROR_SYNTAX => 'syntax error',
730  MDB2_ERROR_UNSUPPORTED => 'not supported',
731  MDB2_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
732  MDB2_ERROR_INVALID_DSN => 'invalid DSN',
733  MDB2_ERROR_CONNECT_FAILED => 'connect failed',
734  MDB2_ERROR_NEED_MORE_DATA => 'insufficient data supplied',
735  MDB2_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
736  MDB2_ERROR_NOSUCHDB => 'no such database',
737  MDB2_ERROR_ACCESS_VIOLATION => 'insufficient permissions',
738  MDB2_ERROR_LOADMODULE => 'error while including on demand module',
739  MDB2_ERROR_TRUNCATED => 'truncated',
740  MDB2_ERROR_DEADLOCK => 'deadlock detected',
741  );
742  }
743 
744  if (is_null($value)) {
745  return $errorMessages;
746  }
747 
748  if (PEAR::isError($value)) {
749  $value = $value->getCode();
750  }
751 
752  return isset($errorMessages[$value]) ?
753  $errorMessages[$value] : $errorMessages[MDB2_ERROR];
754  }
755 
756  // }}}
757  // {{{ function parseDSN($dsn)
758 
796  function parseDSN($dsn)
797  {
798  $parsed = $GLOBALS['_MDB2_dsninfo_default'];
799 
800  if (is_array($dsn)) {
801  $dsn = array_merge($parsed, $dsn);
802  if (!$dsn['dbsyntax']) {
803  $dsn['dbsyntax'] = $dsn['phptype'];
804  }
805  return $dsn;
806  }
807 
808  // Find phptype and dbsyntax
809  if (($pos = strpos($dsn, '://')) !== false) {
810  $str = substr($dsn, 0, $pos);
811  $dsn = substr($dsn, $pos + 3);
812  } else {
813  $str = $dsn;
814  $dsn = null;
815  }
816 
817  // Get phptype and dbsyntax
818  // $str => phptype(dbsyntax)
819  if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
820  $parsed['phptype'] = $arr[1];
821  $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
822  } else {
823  $parsed['phptype'] = $str;
824  $parsed['dbsyntax'] = $str;
825  }
826 
827  if (!count($dsn)) {
828  return $parsed;
829  }
830 
831  // Get (if found): username and password
832  // $dsn => username:password@protocol+hostspec/database
833  if (($at = strrpos($dsn,'@')) !== false) {
834  $str = substr($dsn, 0, $at);
835  $dsn = substr($dsn, $at + 1);
836  if (($pos = strpos($str, ':')) !== false) {
837  $parsed['username'] = rawurldecode(substr($str, 0, $pos));
838  $parsed['password'] = rawurldecode(substr($str, $pos + 1));
839  } else {
840  $parsed['username'] = rawurldecode($str);
841  }
842  }
843 
844  // Find protocol and hostspec
845 
846  // $dsn => proto(proto_opts)/database
847  if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
848  $proto = $match[1];
849  $proto_opts = $match[2] ? $match[2] : false;
850  $dsn = $match[3];
851 
852  // $dsn => protocol+hostspec/database (old format)
853  } else {
854  if (strpos($dsn, '+') !== false) {
855  list($proto, $dsn) = explode('+', $dsn, 2);
856  }
857  if ( strpos($dsn, '//') === 0
858  && strpos($dsn, '/', 2) !== false
859  && $parsed['phptype'] == 'oci8'
860  ) {
861  //oracle's "Easy Connect" syntax:
862  //"username/password@[//]host[:port][/service_name]"
863  //e.g. "scott/tiger@//mymachine:1521/oracle"
864  $proto_opts = $dsn;
865  $dsn = null;
866  } elseif (strpos($dsn, '/') !== false) {
867  list($proto_opts, $dsn) = explode('/', $dsn, 2);
868  } else {
869  $proto_opts = $dsn;
870  $dsn = null;
871  }
872  }
873 
874  // process the different protocol options
875  $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
876  $proto_opts = rawurldecode($proto_opts);
877  if (strpos($proto_opts, ':') !== false) {
878  list($proto_opts, $parsed['port']) = explode(':', $proto_opts);
879  }
880  if ($parsed['protocol'] == 'tcp') {
881  $parsed['hostspec'] = $proto_opts;
882  } elseif ($parsed['protocol'] == 'unix') {
883  $parsed['socket'] = $proto_opts;
884  }
885 
886  // Get dabase if any
887  // $dsn => database
888  if ($dsn) {
889  // /database
890  if (($pos = strpos($dsn, '?')) === false) {
891  $parsed['database'] = $dsn;
892  // /database?param1=value1&param2=value2
893  } else {
894  $parsed['database'] = substr($dsn, 0, $pos);
895  $dsn = substr($dsn, $pos + 1);
896  if (strpos($dsn, '&') !== false) {
897  $opts = explode('&', $dsn);
898  } else { // database?param1=value1
899  $opts = array($dsn);
900  }
901  foreach ($opts as $opt) {
902  list($key, $value) = explode('=', $opt);
903  if (!isset($parsed[$key])) {
904  // don't allow params overwrite
905  $parsed[$key] = rawurldecode($value);
906  }
907  }
908  }
909  }
910 
911  return $parsed;
912  }
913 
914  // }}}
915  // {{{ function fileExists($file)
916 
926  function fileExists($file)
927  {
928  // safe_mode does notwork with is_readable()
929  if (!@ini_get('safe_mode')) {
930  $dirs = explode(PATH_SEPARATOR, ini_get('include_path'));
931  foreach ($dirs as $dir) {
932  if (@is_readable($dir . DIRECTORY_SEPARATOR . $file)) {
933  return true;
934  }
935  }
936  } else {
937  $fp = @fopen($file, 'r', true);
938  if (is_resource($fp)) {
939  @fclose($fp);
940  return true;
941  }
942  }
943  return false;
944  }
945  // }}}
946 }
947 
948 // }}}
949 // {{{ class MDB2_Error extends PEAR_Error
950 
959 class MDB2_Error extends PEAR_Error
960 {
961  // {{{ constructor: function MDB2_Error($code = MDB2_ERROR, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE, $debuginfo = null)
962 
972  $level = E_USER_NOTICE, $debuginfo = null)
973  {
974  if (is_null($code)) {
975  $code = MDB2_ERROR;
976  }
977  parent::__construct('MDB2 Error: '.MDB2::errorMessage($code), $code,
978  $mode, $level, $debuginfo);
979  }
980 
981  // }}}
982 }
983 
984 // }}}
985 // {{{ class MDB2_Driver_Common extends PEAR
986 
995 {
996  // {{{ Variables (Properties)
997 
1003  var $db_index = 0;
1004 
1010  var $dsn = array();
1011 
1017  var $connected_dsn = array();
1018 
1024  var $connection = 0;
1025 
1032 
1038  var $database_name = '';
1039 
1045  var $connected_database_name = '';
1046 
1052  var $connected_server_info = '';
1053 
1059  var $supported = array(
1060  'sequences' => false,
1061  'indexes' => false,
1062  'affected_rows' => false,
1063  'summary_functions' => false,
1064  'order_by_text' => false,
1065  'transactions' => false,
1066  'savepoints' => false,
1067  'current_id' => false,
1068  'limit_queries' => false,
1069  'LOBs' => false,
1070  'replace' => false,
1071  'sub_selects' => false,
1072  'auto_increment' => false,
1073  'primary_key' => false,
1074  'result_introspection' => false,
1075  'prepared_statements' => false,
1076  'identifier_quoting' => false,
1077  'pattern_escaping' => false,
1078  'new_link' => false,
1079  );
1080 
1128  'ssl' => false,
1129  'field_case' => CASE_LOWER,
1130  'disable_query' => false,
1131  'result_class' => 'MDB2_Result_%s',
1132  'buffered_result_class' => 'MDB2_BufferedResult_%s',
1133  'result_wrap_class' => false,
1134  'result_buffering' => true,
1135  'fetch_class' => 'stdClass',
1136  'persistent' => false,
1137  'debug' => 0,
1138  'debug_handler' => 'MDB2_defaultDebugOutput',
1139  'debug_expanded_output' => false,
1140  'default_text_field_length' => 4096,
1141  'lob_buffer_length' => 8192,
1142  'log_line_break' => "\n",
1143  'idxname_format' => '%s_idx',
1144  'seqname_format' => '%s_seq',
1145  'savepoint_format' => 'MDB2_SAVEPOINT_%s',
1146  'statement_format' => 'MDB2_STATEMENT_%1$s_%2$s',
1147  'seqcol_name' => 'sequence',
1148  'quote_identifier' => false,
1149  'use_transactions' => true,
1150  'decimal_places' => 2,
1151  'portability' => MDB2_PORTABILITY_ALL,
1152  'modules' => array(
1153  'ex' => 'Extended',
1154  'dt' => 'Datatype',
1155  'mg' => 'Manager',
1156  'rv' => 'Reverse',
1157  'na' => 'Native',
1158  'fc' => 'Function',
1159  ),
1160  'emulate_prepared' => false,
1161  'datatype_map' => array(),
1162  'datatype_map_callback' => array(),
1163  'nativetype_map_callback' => array(),
1164  );
1165 
1171  var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => false, 'escape_pattern' => false);
1172 
1178  var $identifier_quoting = array('start' => '"', 'end' => '"', 'escape' => '"');
1179 
1185  var $sql_comments = array(
1186  array('start' => '--', 'end' => "\n", 'escape' => false),
1187  array('start' => '/*', 'end' => '*/', 'escape' => false),
1188  );
1189 
1195  var $wildcards = array('%', '_');
1196 
1202  var $as_keyword = ' AS ';
1203 
1209  var $warnings = array();
1210 
1216  var $debug_output = '';
1217 
1223  var $in_transaction = false;
1224 
1230  var $nested_transaction_counter = null;
1231 
1237  var $has_transaction_error = false;
1238 
1244  var $offset = 0;
1245 
1251  var $limit = 0;
1252 
1259 
1266 
1273 
1279  var $fetchmode = MDB2_FETCHMODE_ORDERED;
1280 
1286  var $modules = array();
1287 
1293  var $destructor_registered = true;
1294 
1295  // }}}
1296  // {{{ constructor: function __construct()
1297 
1301  function __construct()
1302  {
1303  end($GLOBALS['_MDB2_databases']);
1304  $db_index = key($GLOBALS['_MDB2_databases']) + 1;
1305  $GLOBALS['_MDB2_databases'][$db_index] = &$this;
1306  $this->db_index = $db_index;
1307  }
1308 
1309  // }}}
1310  // {{{ function MDB2_Driver_Common()
1311 
1316  {
1317  $this->destructor_registered = false;
1318  $this->__construct();
1319  }
1320 
1321  // }}}
1322  // {{{ destructor: function __destruct()
1323 
1327  function __destruct()
1328  {
1329  $this->disconnect(false);
1330  }
1331 
1332  // }}}
1333  // {{{ function free()
1334 
1342  function free()
1343  {
1344  unset($GLOBALS['_MDB2_databases'][$this->db_index]);
1345  unset($this->db_index);
1346  return MDB2_OK;
1347  }
1348 
1349  // }}}
1350  // {{{ function __toString()
1351 
1359  function __toString()
1360  {
1361  $info = get_class($this);
1362  $info.= ': (phptype = '.$this->phptype.', dbsyntax = '.$this->dbsyntax.')';
1363  if ($this->connection) {
1364  $info.= ' [connected]';
1365  }
1366  return $info;
1367  }
1368 
1369  // }}}
1370  // {{{ function errorInfo($error = null)
1371 
1381  function errorInfo($error = null)
1382  {
1383  return array($error, null, null);
1384  }
1385 
1386  // }}}
1387  // {{{ function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
1388 
1412  function &raiseError($code = null, $mode = null, $options = null, $userinfo = null, $method = null)
1413  {
1414  $userinfo = "[Error message: $userinfo]\n";
1415  // The error is yet a MDB2 error object
1416  if (PEAR::isError($code)) {
1417  // because we use the static PEAR::raiseError, our global
1418  // handler should be used if it is set
1419  if (is_null($mode) && !empty($this->_default_error_mode)) {
1420  $mode = $this->_default_error_mode;
1421  $options = $this->_default_error_options;
1422  }
1423  if (is_null($userinfo)) {
1424  $userinfo = $code->getUserinfo();
1425  }
1426  $code = $code->getCode();
1427  } elseif ($code == MDB2_ERROR_NOT_FOUND) {
1428  // extension not loaded: don't call $this->errorInfo() or the script
1429  // will die
1430  } elseif (isset($this->connection)) {
1431  if (!empty($this->last_query)) {
1432  $userinfo.= "[Last executed query: {$this->last_query}]\n";
1433  }
1434  $native_errno = $native_msg = null;
1435  list($code, $native_errno, $native_msg) = $this->errorInfo($code);
1436  if (!is_null($native_errno) && $native_errno !== '') {
1437  $userinfo.= "[Native code: $native_errno]\n";
1438  }
1439  if (!is_null($native_msg) && $native_msg !== '') {
1440  $userinfo.= "[Native message: ". strip_tags($native_msg) ."]\n";
1441  }
1442  if (!is_null($method)) {
1443  $userinfo = $method.': '.$userinfo;
1444  }
1445  }
1446 
1447  $err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
1448  if ($err->getMode() !== PEAR_ERROR_RETURN
1449  && isset($this->nested_transaction_counter) && !$this->has_transaction_error) {
1450  $this->has_transaction_error =& $err;
1451  }
1452  return $err;
1453  }
1454 
1455  // }}}
1456  // {{{ function resetWarnings()
1457 
1465  function resetWarnings()
1466  {
1467  $this->warnings = array();
1468  }
1469 
1470  // }}}
1471  // {{{ function getWarnings()
1472 
1482  function getWarnings()
1483  {
1484  return array_reverse($this->warnings);
1485  }
1486 
1487  // }}}
1488  // {{{ function setFetchMode($fetchmode, $object_class = 'stdClass')
1489 
1509  function setFetchMode($fetchmode, $object_class = 'stdClass')
1510  {
1511  switch ($fetchmode) {
1512  case MDB2_FETCHMODE_OBJECT:
1513  $this->options['fetch_class'] = $object_class;
1515  case MDB2_FETCHMODE_ASSOC:
1516  $this->fetchmode = $fetchmode;
1517  break;
1518  default:
1519  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1520  'invalid fetchmode mode', __FUNCTION__);
1521  }
1522 
1523  return MDB2_OK;
1524  }
1525 
1526  // }}}
1527  // {{{ function setOption($option, $value)
1528 
1539  function setOption($option, $value)
1540  {
1541  if (array_key_exists($option, $this->options)) {
1542  $this->options[$option] = $value;
1543  return MDB2_OK;
1544  }
1545  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1546  "unknown option $option", __FUNCTION__);
1547  }
1548 
1549  // }}}
1550  // {{{ function getOption($option)
1551 
1561  function getOption($option)
1562  {
1563  if (array_key_exists($option, $this->options)) {
1564  return $this->options[$option];
1565  }
1566  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1567  "unknown option $option", __FUNCTION__);
1568  }
1569 
1570  // }}}
1571  // {{{ function debug($message, $scope = '', $is_manip = null)
1572 
1587  function debug($message, $scope = '', $context = array())
1588  {
1589  if ($this->options['debug'] && $this->options['debug_handler']) {
1590  if (!$this->options['debug_expanded_output']) {
1591  if (!empty($context['when']) && $context['when'] !== 'pre') {
1592  return null;
1593  }
1594  $context = empty($context['is_manip']) ? false : $context['is_manip'];
1595  }
1596  return call_user_func_array($this->options['debug_handler'], array(&$this, $scope, $message, $context));
1597  }
1598  return null;
1599  }
1600 
1601  // }}}
1602  // {{{ function getDebugOutput()
1603 
1611  function getDebugOutput()
1612  {
1613  return $this->debug_output;
1614  }
1615 
1616  // }}}
1617  // {{{ function escape($text)
1618 
1630  function escape($text, $escape_wildcards = false)
1631  {
1632  if ($escape_wildcards) {
1633  $text = $this->escapePattern($text);
1634  }
1635 
1636  $text = str_replace($this->string_quoting['end'], $this->string_quoting['escape'] . $this->string_quoting['end'], $text);
1637  return $text;
1638  }
1639 
1640  // }}}
1641  // {{{ function escapePattern($text)
1642 
1658  {
1659  if ($this->string_quoting['escape_pattern']) {
1660  $text = str_replace($this->string_quoting['escape_pattern'], $this->string_quoting['escape_pattern'] . $this->string_quoting['escape_pattern'], $text);
1661  foreach ($this->wildcards as $wildcard) {
1662  $text = str_replace($wildcard, $this->string_quoting['escape_pattern'] . $wildcard, $text);
1663  }
1664  }
1665  return $text;
1666  }
1667 
1668  // }}}
1669  // {{{ function quoteIdentifier($str, $check_option = false)
1670 
1705  function quoteIdentifier($str, $check_option = false)
1706  {
1707  if ($check_option && !$this->options['quote_identifier']) {
1708  return $str;
1709  }
1710  $str = str_replace($this->identifier_quoting['end'], $this->identifier_quoting['escape'] . $this->identifier_quoting['end'], $str);
1711  return $this->identifier_quoting['start'] . $str . $this->identifier_quoting['end'];
1712  }
1713 
1714  // }}}
1715  // {{{ function getAsKeyword()
1716 
1722  function getAsKeyword()
1723  {
1724  return $this->as_keyword;
1725  }
1726 
1727  // }}}
1728  // {{{ function getConnection()
1729 
1738  function getConnection()
1739  {
1740  $result = $this->connect();
1741  if (PEAR::isError($result)) {
1742  return $result;
1743  }
1744  return $this->connection;
1745  }
1746 
1747  // }}}
1748  // {{{ function _fixResultArrayValues(&$row, $mode)
1749 
1760  function _fixResultArrayValues(&$row, $mode)
1761  {
1762  switch ($mode) {
1764  foreach ($row as $key => $value) {
1765  if ($value === '') {
1766  $row[$key] = null;
1767  }
1768  }
1769  break;
1771  foreach ($row as $key => $value) {
1772  if (is_string($value)) {
1773  $row[$key] = rtrim($value);
1774  }
1775  }
1776  break;
1778  $tmp_row = array();
1779  foreach ($row as $key => $value) {
1780  $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1781  }
1782  $row = $tmp_row;
1783  break;
1785  foreach ($row as $key => $value) {
1786  if ($value === '') {
1787  $row[$key] = null;
1788  } elseif (is_string($value)) {
1789  $row[$key] = rtrim($value);
1790  }
1791  }
1792  break;
1794  $tmp_row = array();
1795  foreach ($row as $key => $value) {
1796  if (is_string($value)) {
1797  $value = rtrim($value);
1798  }
1799  $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1800  }
1801  $row = $tmp_row;
1802  break;
1804  $tmp_row = array();
1805  foreach ($row as $key => $value) {
1806  if ($value === '') {
1807  $value = null;
1808  }
1809  $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1810  }
1811  $row = $tmp_row;
1812  break;
1814  $tmp_row = array();
1815  foreach ($row as $key => $value) {
1816  if ($value === '') {
1817  $value = null;
1818  } elseif (is_string($value)) {
1819  $value = rtrim($value);
1820  }
1821  $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1822  }
1823  $row = $tmp_row;
1824  break;
1825  }
1826  }
1827 
1828  // }}}
1829  // {{{ function &loadModule($module, $property = null, $phptype_specific = null)
1830 
1845  function &loadModule($module, $property = null, $phptype_specific = null)
1846  {
1847  if (!$property) {
1848  $property = strtolower($module);
1849  }
1850 
1851  if (!isset($this->{$property})) {
1852  $version = $phptype_specific;
1853  if ($phptype_specific !== false) {
1854  $version = true;
1855  $class_name = 'MDB2_Driver_'.$module.'_'.$this->phptype;
1856  $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php';
1857  }
1858  if ($phptype_specific === false
1859  || (!MDB2::classExists($class_name) && !MDB2::fileExists($file_name))
1860  ) {
1861  $version = false;
1862  $class_name = 'MDB2_'.$module;
1863  $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php';
1864  }
1865 
1866  $err = MDB2::loadClass($class_name, $this->getOption('debug'));
1867  if (PEAR::isError($err)) {
1868  return $err;
1869  }
1870 
1871  // load modul in a specific version
1872  if ($version) {
1873  if (method_exists($class_name, 'getClassName')) {
1874  $class_name_new = call_user_func(array($class_name, 'getClassName'), $this->db_index);
1875  if ($class_name != $class_name_new) {
1876  $class_name = $class_name_new;
1877  $err = MDB2::loadClass($class_name, $this->getOption('debug'));
1878  if (PEAR::isError($err)) {
1879  return $err;
1880  }
1881  }
1882  }
1883  }
1884 
1885  if (!MDB2::classExists($class_name)) {
1886  $err =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null,
1887  "unable to load module '$module' into property '$property'", __FUNCTION__);
1888  return $err;
1889  }
1890  $this->{$property} = new $class_name($this->db_index);
1891  $this->modules[$module] =& $this->{$property};
1892  if ($version) {
1893  // this will be used in the connect method to determine if the module
1894  // needs to be loaded with a different version if the server
1895  // version changed in between connects
1896  $this->loaded_version_modules[] = $property;
1897  }
1898  }
1899 
1900  return $this->{$property};
1901  }
1902 
1903  // }}}
1904  // {{{ function __call($method, $params)
1905 
1914  function __call($method, $params)
1915  {
1916  $module = null;
1917  if (preg_match('/^([a-z]+)([A-Z])(.*)$/', $method, $match)
1918  && isset($this->options['modules'][$match[1]])
1919  ) {
1920  $module = $this->options['modules'][$match[1]];
1921  $method = strtolower($match[2]).$match[3];
1922  if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) {
1923  $result =& $this->loadModule($module);
1924  if (PEAR::isError($result)) {
1925  return $result;
1926  }
1927  }
1928  } else {
1929  foreach ($this->modules as $key => $foo) {
1930  if (is_object($this->modules[$key])
1931  && method_exists($this->modules[$key], $method)
1932  ) {
1933  $module = $key;
1934  break;
1935  }
1936  }
1937  }
1938  if (!is_null($module)) {
1939  return call_user_func_array(array(&$this->modules[$module], $method), $params);
1940  }
1941  trigger_error(sprintf('Call to undefined function: %s::%s().', get_class($this), $method), E_USER_ERROR);
1942  }
1943 
1944  // }}}
1945  // {{{ function beginTransaction($savepoint = null)
1946 
1955  function beginTransaction($savepoint = null)
1956  {
1957  $this->debug('Starting transaction', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
1958  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1959  'transactions are not supported', __FUNCTION__);
1960  }
1961 
1962  // }}}
1963  // {{{ function commit($savepoint = null)
1964 
1976  function commit($savepoint = null)
1977  {
1978  $this->debug('Committing transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
1979  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1980  'commiting transactions is not supported', __FUNCTION__);
1981  }
1982 
1983  // }}}
1984  // {{{ function rollback($savepoint = null)
1985 
1997  function rollback($savepoint = null)
1998  {
1999  $this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
2000  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2001  'rolling back transactions is not supported', __FUNCTION__);
2002  }
2003 
2004  // }}}
2005  // {{{ function inTransaction($ignore_nested = false)
2006 
2018  function inTransaction($ignore_nested = false)
2019  {
2020  if (!$ignore_nested && isset($this->nested_transaction_counter)) {
2021  return $this->nested_transaction_counter;
2022  }
2023  return $this->in_transaction;
2024  }
2025 
2026  // }}}
2027  // {{{ function setTransactionIsolation($isolation)
2028 
2045  function setTransactionIsolation($isolation, $options = array())
2046  {
2047  $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
2048  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2049  'isolation level setting is not supported', __FUNCTION__);
2050  }
2051 
2052  // }}}
2053  // {{{ function beginNestedTransaction($savepoint = false)
2054 
2069  {
2070  if ($this->in_transaction) {
2071  ++$this->nested_transaction_counter;
2072  $savepoint = sprintf($this->options['savepoint_format'], $this->nested_transaction_counter);
2073  if ($this->supports('savepoints') && $savepoint) {
2074  return $this->beginTransaction($savepoint);
2075  }
2076  return MDB2_OK;
2077  }
2078  $this->has_transaction_error = false;
2079  $result = $this->beginTransaction();
2080  $this->nested_transaction_counter = 1;
2081  return $result;
2082  }
2083 
2084  // }}}
2085  // {{{ function completeNestedTransaction($force_rollback = false, $release = false)
2086 
2104  function completeNestedTransaction($force_rollback = false)
2105  {
2106  if ($this->nested_transaction_counter > 1) {
2107  $savepoint = sprintf($this->options['savepoint_format'], $this->nested_transaction_counter);
2108  if ($this->supports('savepoints') && $savepoint) {
2109  if ($force_rollback || $this->has_transaction_error) {
2110  $result = $this->rollback($savepoint);
2111  if (!PEAR::isError($result)) {
2112  $result = false;
2113  $this->has_transaction_error = false;
2114  }
2115  } else {
2116  $result = $this->commit($savepoint);
2117  }
2118  } else {
2119  $result = MDB2_OK;
2120  }
2121  --$this->nested_transaction_counter;
2122  return $result;
2123  }
2124 
2125  $this->nested_transaction_counter = null;
2126  $result = MDB2_OK;
2127 
2128  // transaction has not yet been rolled back
2129  if ($this->in_transaction) {
2130  if ($force_rollback || $this->has_transaction_error) {
2131  $result = $this->rollback();
2132  if (!PEAR::isError($result)) {
2133  $result = false;
2134  }
2135  } else {
2136  $result = $this->commit();
2137  }
2138  }
2139  $this->has_transaction_error = false;
2140  return $result;
2141  }
2142 
2143  // }}}
2144  // {{{ function failNestedTransaction($error = null, $immediately = false)
2145 
2161  function failNestedTransaction($error = null, $immediately = false)
2162  {
2163  if (is_null($error)) {
2164  $error = $this->has_transaction_error ? $this->has_transaction_error : true;
2165  } elseif (!$error) {
2166  $error = true;
2167  }
2168  $this->has_transaction_error = $error;
2169  if (!$immediately) {
2170  return MDB2_OK;
2171  }
2172  return $this->rollback();
2173  }
2174 
2175  // }}}
2176  // {{{ function getNestedTransactionError()
2177 
2192  {
2193  return $this->has_transaction_error;
2194  }
2195 
2196  // }}}
2197  // {{{ connect()
2198 
2204  function connect()
2205  {
2206  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2207  'method not implemented', __FUNCTION__);
2208  }
2209 
2210  // }}}
2211  // {{{ setCharset($charset, $connection = null)
2212 
2221  function setCharset($charset, $connection = null)
2222  {
2223  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2224  'method not implemented', __FUNCTION__);
2225  }
2226 
2227  // }}}
2228  // {{{ function disconnect($force = true)
2229 
2241  function disconnect($force = true)
2242  {
2243  $this->connection = 0;
2244  $this->connected_dsn = array();
2245  $this->connected_database_name = '';
2246  $this->opened_persistent = null;
2247  $this->connected_server_info = '';
2248  $this->in_transaction = null;
2249  $this->nested_transaction_counter = null;
2250  return MDB2_OK;
2251  }
2252 
2253  // }}}
2254  // {{{ function setDatabase($name)
2255 
2265  function setDatabase($name)
2266  {
2267  $previous_database_name = (isset($this->database_name)) ? $this->database_name : '';
2268  $this->database_name = $name;
2269  $this->disconnect(false);
2270  return $previous_database_name;
2271  }
2272 
2273  // }}}
2274  // {{{ function getDatabase()
2275 
2283  function getDatabase()
2284  {
2285  return $this->database_name;
2286  }
2287 
2288  // }}}
2289  // {{{ function setDSN($dsn)
2290 
2300  function setDSN($dsn)
2301  {
2302  $dsn_default = $GLOBALS['_MDB2_dsninfo_default'];
2303  $dsn = MDB2::parseDSN($dsn);
2304  if (array_key_exists('database', $dsn)) {
2305  $this->database_name = $dsn['database'];
2306  unset($dsn['database']);
2307  }
2308  $this->dsn = array_merge($dsn_default, $dsn);
2309  return $this->disconnect(false);
2310  }
2311 
2312  // }}}
2313  // {{{ function getDSN($type = 'string', $hidepw = false)
2314 
2325  function getDSN($type = 'string', $hidepw = false)
2326  {
2327  $dsn = array_merge($GLOBALS['_MDB2_dsninfo_default'], $this->dsn);
2328  $dsn['phptype'] = $this->phptype;
2329  $dsn['database'] = $this->database_name;
2330  if ($hidepw) {
2331  $dsn['password'] = $hidepw;
2332  }
2333  switch ($type) {
2334  // expand to include all possible options
2335  case 'string':
2336  $dsn = $dsn['phptype'].
2337  ($dsn['dbsyntax'] ? ('('.$dsn['dbsyntax'].')') : '').
2338  '://'.$dsn['username'].':'.
2339  $dsn['password'].'@'.$dsn['hostspec'].
2340  ($dsn['port'] ? (':'.$dsn['port']) : '').
2341  '/'.$dsn['database'];
2342  break;
2343  case 'array':
2344  default:
2345  break;
2346  }
2347  return $dsn;
2348  }
2349 
2350  // }}}
2351  // {{{ function &standaloneQuery($query, $types = null, $is_manip = false)
2352 
2365  function &standaloneQuery($query, $types = null, $is_manip = false)
2366  {
2367  $offset = $this->offset;
2368  $limit = $this->limit;
2369  $this->offset = $this->limit = 0;
2370  $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
2371 
2372  $connection = $this->getConnection();
2373  if (PEAR::isError($connection)) {
2374  return $connection;
2375  }
2376 
2377  $result =& $this->_doQuery($query, $is_manip, $connection, false);
2378  if (PEAR::isError($result)) {
2379  return $result;
2380  }
2381 
2382  if ($is_manip) {
2383  $affected_rows = $this->_affectedRows($connection, $result);
2384  return $affected_rows;
2385  }
2386  $result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
2387  return $result;
2388  }
2389 
2390  // }}}
2391  // {{{ function _modifyQuery($query, $is_manip, $limit, $offset)
2392 
2405  function _modifyQuery($query, $is_manip, $limit, $offset)
2406  {
2407  return $query;
2408  }
2409 
2410  // }}}
2411  // {{{ function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
2412 
2424  function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
2425  {
2426  $this->last_query = $query;
2427  $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
2428  if ($result) {
2429  if (PEAR::isError($result)) {
2430  return $result;
2431  }
2432  $query = $result;
2433  }
2434  $err =& $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2435  'method not implemented', __FUNCTION__);
2436  return $err;
2437  }
2438 
2439  // }}}
2440  // {{{ function _affectedRows($connection, $result = null)
2441 
2452  function _affectedRows($connection, $result = null)
2453  {
2454  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2455  'method not implemented', __FUNCTION__);
2456  }
2457 
2458  // }}}
2459  // {{{ function &exec($query)
2460 
2470  function &exec($query)
2471  {
2472  $offset = $this->offset;
2473  $limit = $this->limit;
2474  $this->offset = $this->limit = 0;
2475  $query = $this->_modifyQuery($query, true, $limit, $offset);
2476 
2477  $connection = $this->getConnection();
2478  if (PEAR::isError($connection)) {
2479  return $connection;
2480  }
2481 
2482  $result =& $this->_doQuery($query, true, $connection, $this->database_name);
2483  if (PEAR::isError($result)) {
2484  return $result;
2485  }
2486 
2487  $affectedRows = $this->_affectedRows($connection, $result);
2488  return $affectedRows;
2489  }
2490 
2491  // }}}
2492  // {{{ function &query($query, $types = null, $result_class = true, $result_wrap_class = false)
2493 
2507  function &query($query, $types = null, $result_class = true, $result_wrap_class = false)
2508  {
2509  $offset = $this->offset;
2510  $limit = $this->limit;
2511  $this->offset = $this->limit = 0;
2512  $query = $this->_modifyQuery($query, false, $limit, $offset);
2513 
2514  $connection = $this->getConnection();
2515  if (PEAR::isError($connection)) {
2516  return $connection;
2517  }
2518 
2519  $result =& $this->_doQuery($query, false, $connection, $this->database_name);
2520  if (PEAR::isError($result)) {
2521  return $result;
2522  }
2523 
2524  $result =& $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset);
2525  return $result;
2526  }
2527 
2528  // }}}
2529  // {{{ function &_wrapResult($result, $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null)
2530 
2546  function &_wrapResult($result, $types = array(), $result_class = true,
2547  $result_wrap_class = false, $limit = null, $offset = null)
2548  {
2549  if ($types === true) {
2550  if ($this->supports('result_introspection')) {
2551  $this->loadModule('Reverse', null, true);
2552  $tableInfo = $this->reverse->tableInfo($result);
2553  if (PEAR::isError($tableInfo)) {
2554  return $tableInfo;
2555  }
2556  $types = array();
2557  foreach ($tableInfo as $field) {
2558  $types[] = $field['mdb2type'];
2559  }
2560  } else {
2561  $types = null;
2562  }
2563  }
2564 
2565  if ($result_class === true) {
2566  $result_class = $this->options['result_buffering']
2567  ? $this->options['buffered_result_class'] : $this->options['result_class'];
2568  }
2569 
2570  if ($result_class) {
2571  $class_name = sprintf($result_class, $this->phptype);
2572  if (!MDB2::classExists($class_name)) {
2573  $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
2574  'result class does not exist '.$class_name, __FUNCTION__);
2575  return $err;
2576  }
2577  $result = new $class_name($this, $result, $limit, $offset);
2578  if (!MDB2::isResultCommon($result)) {
2579  $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
2580  'result class is not extended from MDB2_Result_Common', __FUNCTION__);
2581  return $err;
2582  }
2583  if (!empty($types)) {
2584  $err = $result->setResultTypes($types);
2585  if (PEAR::isError($err)) {
2586  $result->free();
2587  return $err;
2588  }
2589  }
2590  }
2591  if ($result_wrap_class === true) {
2592  $result_wrap_class = $this->options['result_wrap_class'];
2593  }
2594  if ($result_wrap_class) {
2595  if (!MDB2::classExists($result_wrap_class)) {
2596  $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
2597  'result wrap class does not exist '.$result_wrap_class, __FUNCTION__);
2598  return $err;
2599  }
2600  $result = new $result_wrap_class($result, $this->fetchmode);
2601  }
2602  return $result;
2603  }
2604 
2605  // }}}
2606  // {{{ function getServerVersion($native = false)
2607 
2617  function getServerVersion($native = false)
2618  {
2619  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2620  'method not implemented', __FUNCTION__);
2621  }
2622 
2623  // }}}
2624  // {{{ function setLimit($limit, $offset = null)
2625 
2636  function setLimit($limit, $offset = null)
2637  {
2638  if (!$this->supports('limit_queries')) {
2639  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2640  'limit is not supported by this driver', __FUNCTION__);
2641  }
2642  $limit = (int)$limit;
2643  if ($limit < 0) {
2644  return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2645  'it was not specified a valid selected range row limit', __FUNCTION__);
2646  }
2647  $this->limit = $limit;
2648  if (!is_null($offset)) {
2649  $offset = (int)$offset;
2650  if ($offset < 0) {
2651  return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2652  'it was not specified a valid first selected range row', __FUNCTION__);
2653  }
2654  $this->offset = $offset;
2655  }
2656  return MDB2_OK;
2657  }
2658 
2659  // }}}
2660  // {{{ function subSelect($query, $type = false)
2661 
2674  function subSelect($query, $type = false)
2675  {
2676  if ($this->supports('sub_selects') === true) {
2677  return $query;
2678  }
2679 
2680  if (!$this->supports('sub_selects')) {
2681  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2682  'method not implemented', __FUNCTION__);
2683  }
2684 
2685  $col = $this->queryCol($query, $type);
2686  if (PEAR::isError($col)) {
2687  return $col;
2688  }
2689  if (!is_array($col) || count($col) == 0) {
2690  return 'NULL';
2691  }
2692  if ($type) {
2693  $this->loadModule('Datatype', null, true);
2694  return $this->datatype->implodeArray($col, $type);
2695  }
2696  return implode(', ', $col);
2697  }
2698 
2699  // }}}
2700  // {{{ function replace($table, $fields)
2701 
2765  function replace($table, $fields)
2766  {
2767  if (!$this->supports('replace')) {
2768  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2769  'replace query is not supported', __FUNCTION__);
2770  }
2771  $count = count($fields);
2772  $condition = $values = array();
2773  for ($colnum = 0, reset($fields); $colnum < $count; next($fields), $colnum++) {
2774  $name = key($fields);
2775  if (isset($fields[$name]['null']) && $fields[$name]['null']) {
2776  $value = 'NULL';
2777  } else {
2778  $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
2779  $value = $this->quote($fields[$name]['value'], $type);
2780  }
2781  $values[$name] = $value;
2782  if (isset($fields[$name]['key']) && $fields[$name]['key']) {
2783  if ($value === 'NULL') {
2784  return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
2785  'key value '.$name.' may not be NULL', __FUNCTION__);
2786  }
2787  $condition[] = $name . '=' . $value;
2788  }
2789  }
2790  if (empty($condition)) {
2791  return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
2792  'not specified which fields are keys', __FUNCTION__);
2793  }
2794 
2795  $result = null;
2796  $in_transaction = $this->in_transaction;
2797  if (!$in_transaction && PEAR::isError($result = $this->beginTransaction())) {
2798  return $result;
2799  }
2800 
2801  $connection = $this->getConnection();
2802  if (PEAR::isError($connection)) {
2803  return $connection;
2804  }
2805 
2806  $condition = ' WHERE '.implode(' AND ', $condition);
2807  $query = "DELETE FROM $table$condition";
2808  $result =& $this->_doQuery($query, true, $connection);
2809  if (!PEAR::isError($result)) {
2810  $affected_rows = $this->_affectedRows($connection, $result);
2811  $insert = implode(', ', array_keys($values));
2812  $values = implode(', ', $values);
2813  $query = "INSERT INTO $table ($insert) VALUES ($values)";
2814  $result =& $this->_doQuery($query, true, $connection);
2815  if (!PEAR::isError($result)) {
2816  $affected_rows += $this->_affectedRows($connection, $result);;
2817  }
2818  }
2819 
2820  if (!$in_transaction) {
2821  if (PEAR::isError($result)) {
2822  $this->rollback();
2823  } else {
2824  $result = $this->commit();
2825  }
2826  }
2827 
2828  if (PEAR::isError($result)) {
2829  return $result;
2830  }
2831 
2832  return $affected_rows;
2833  }
2834 
2835  // }}}
2836  // {{{ function &prepare($query, $types = null, $result_types = null, $lobs = array())
2837 
2860  function &prepare($query, $types = null, $result_types = null, $lobs = array())
2861  {
2862  $is_manip = ($result_types === MDB2_PREPARE_MANIP);
2863  $offset = $this->offset;
2864  $limit = $this->limit;
2865  $this->offset = $this->limit = 0;
2866  $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
2867  if ($result) {
2868  if (PEAR::isError($result)) {
2869  return $result;
2870  }
2871  $query = $result;
2872  }
2873  $placeholder_type_guess = $placeholder_type = null;
2874  $question = '?';
2875  $colon = ':';
2876  $positions = array();
2877  $position = 0;
2878  $ignores = $this->sql_comments;
2879  $ignores[] = $this->string_quoting;
2880  $ignores[] = $this->identifier_quoting;
2881  while ($position < strlen($query)) {
2882  $q_position = strpos($query, $question, $position);
2883  $c_position = strpos($query, $colon, $position);
2884  if ($q_position && $c_position) {
2885  $p_position = min($q_position, $c_position);
2886  } elseif ($q_position) {
2887  $p_position = $q_position;
2888  } elseif ($c_position) {
2889  $p_position = $c_position;
2890  } else {
2891  break;
2892  }
2893  if (is_null($placeholder_type)) {
2894  $placeholder_type_guess = $query[$p_position];
2895  }
2896 
2897  $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
2898  if (PEAR::isError($new_pos)) {
2899  return $new_pos;
2900  }
2901  if ($new_pos != $position) {
2902  $position = $new_pos;
2903  continue; //evaluate again starting from the new position
2904  }
2905 
2906  if ($query[$position] == $placeholder_type_guess) {
2907  if (is_null($placeholder_type)) {
2908  $placeholder_type = $query[$p_position];
2909  $question = $colon = $placeholder_type;
2910  if (!empty($types) && is_array($types)) {
2911  if ($placeholder_type == ':') {
2912  if (is_int(key($types))) {
2913  $types_tmp = $types;
2914  $types = array();
2915  $count = -1;
2916  }
2917  } else {
2918  $types = array_values($types);
2919  }
2920  }
2921  }
2922  if ($placeholder_type == ':') {
2923  $parameter = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
2924  if ($parameter === '') {
2925  $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2926  'named parameter with an empty name', __FUNCTION__);
2927  return $err;
2928  }
2929  $positions[$p_position] = $parameter;
2930  $query = substr_replace($query, '?', $position, strlen($parameter)+1);
2931  // use parameter name in type array
2932  if (isset($count) && isset($types_tmp[++$count])) {
2933  $types[$parameter] = $types_tmp[$count];
2934  }
2935  } else {
2936  $positions[$p_position] = count($positions);
2937  }
2938  $position = $p_position + 1;
2939  } else {
2940  $position = $p_position;
2941  }
2942  }
2943  $class_name = 'MDB2_Statement_'.$this->phptype;
2944  $statement = null;
2945  $obj = new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
2946  $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
2947  return $obj;
2948  }
2949 
2950  // }}}
2951  // {{{ function _skipDelimitedStrings($query, $position, $p_position)
2952 
2968  function _skipDelimitedStrings($query, $position, $p_position)
2969  {
2970  $ignores = $this->sql_comments;
2971  $ignores[] = $this->string_quoting;
2972  $ignores[] = $this->identifier_quoting;
2973 
2974  foreach ($ignores as $ignore) {
2975  if (!empty($ignore['start'])) {
2976  if (is_int($start_quote = strpos($query, $ignore['start'], $position)) && $start_quote < $p_position) {
2977  $end_quote = $start_quote;
2978  do {
2979  if (!is_int($end_quote = strpos($query, $ignore['end'], $end_quote + 1))) {
2980  if ($ignore['end'] === "\n") {
2981  $end_quote = strlen($query) - 1;
2982  } else {
2983  $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2984  'query with an unterminated text string specified', __FUNCTION__);
2985  return $err;
2986  }
2987  }
2988  } while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']);
2989  $position = $end_quote + 1;
2990  return $position;
2991  }
2992  }
2993  }
2994  return $position;
2995  }
2996 
2997  // }}}
2998  // {{{ function quote($value, $type = null, $quote = true)
2999 
3014  function quote($value, $type = null, $quote = true, $escape_wildcards = false)
3015  {
3016  $result = $this->loadModule('Datatype', null, true);
3017  if (PEAR::isError($result)) {
3018  return $result;
3019  }
3020 
3021  return $this->datatype->quote($value, $type, $quote, $escape_wildcards);
3022  }
3023 
3024  // }}}
3025  // {{{ function getDeclaration($type, $name, $field)
3026 
3040  function getDeclaration($type, $name, $field)
3041  {
3042  $result = $this->loadModule('Datatype', null, true);
3043  if (PEAR::isError($result)) {
3044  return $result;
3045  }
3046  return $this->datatype->getDeclaration($type, $name, $field);
3047  }
3048 
3049  // }}}
3050  // {{{ function compareDefinition($current, $previous)
3051 
3062  function compareDefinition($current, $previous)
3063  {
3064  $result = $this->loadModule('Datatype', null, true);
3065  if (PEAR::isError($result)) {
3066  return $result;
3067  }
3068  return $this->datatype->compareDefinition($current, $previous);
3069  }
3070 
3071  // }}}
3072  // {{{ function supports($feature)
3073 
3086  function supports($feature)
3087  {
3088  if (array_key_exists($feature, $this->supported)) {
3089  return $this->supported[$feature];
3090  }
3091  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3092  "unknown support feature $feature", __FUNCTION__);
3093  }
3094 
3095  // }}}
3096  // {{{ function getSequenceName($sqn)
3097 
3107  function getSequenceName($sqn)
3108  {
3109  return sprintf($this->options['seqname_format'],
3110  preg_replace('/[^a-z0-9_\$.]/i', '_', $sqn));
3111  }
3112 
3113  // }}}
3114  // {{{ function getIndexName($idx)
3115 
3125  function getIndexName($idx)
3126  {
3127  return sprintf($this->options['idxname_format'],
3128  preg_replace('/[^a-z0-9_\$]/i', '_', $idx));
3129  }
3130 
3131  // }}}
3132  // {{{ function nextID($seq_name, $ondemand = true)
3133 
3144  function nextID($seq_name, $ondemand = true)
3145  {
3146  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3147  'method not implemented', __FUNCTION__);
3148  }
3149 
3150  // }}}
3151  // {{{ function lastInsertID($table = null, $field = null)
3152 
3164  function lastInsertID($table = null, $field = null)
3165  {
3166  return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3167  'method not implemented', __FUNCTION__);
3168  }
3169 
3170  // }}}
3171  // {{{ function currID($seq_name)
3172 
3182  function currID($seq_name)
3183  {
3184  $this->warnings[] = 'database does not support getting current
3185  sequence value, the sequence value was incremented';
3186  return $this->nextID($seq_name);
3187  }
3188 
3189  // }}}
3190  // {{{ function queryOne($query, $type = null, $colnum = 0)
3191 
3208  function queryOne($query, $type = null, $colnum = 0)
3209  {
3210  $result = $this->query($query, $type);
3211  if (!MDB2::isResultCommon($result)) {
3212  return $result;
3213  }
3214 
3215  $one = $result->fetchOne($colnum);
3216  $result->free();
3217  return $one;
3218  }
3219 
3220  // }}}
3221  // {{{ function queryRow($query, $types = null, $fetchmode = MDB2_FETCHMODE_DEFAULT)
3222 
3239  function queryRow($query, $types = null, $fetchmode = MDB2_FETCHMODE_DEFAULT)
3240  {
3241  $result = $this->query($query, $types);
3242  if (!MDB2::isResultCommon($result)) {
3243  return $result;
3244  }
3245 
3246  $row = $result->fetchRow($fetchmode);
3247  $result->free();
3248  return $row;
3249  }
3250 
3251  // }}}
3252  // {{{ function queryCol($query, $type = null, $colnum = 0)
3253 
3269  function queryCol($query, $type = null, $colnum = 0)
3270  {
3271  $result = $this->query($query, $type);
3272  if (!MDB2::isResultCommon($result)) {
3273  return $result;
3274  }
3275 
3276  $col = $result->fetchCol($colnum);
3277  $result->free();
3278  return $col;
3279  }
3280 
3281  // }}}
3282  // {{{ function queryAll($query, $types = null, $fetchmode = MDB2_FETCHMODE_DEFAULT, $rekey = false, $force_array = false, $group = false)
3283 
3308  function queryAll($query, $types = null, $fetchmode = MDB2_FETCHMODE_DEFAULT,
3309  $rekey = false, $force_array = false, $group = false)
3310  {
3311  $result = $this->query($query, $types);
3312  if (!MDB2::isResultCommon($result)) {
3313  return $result;
3314  }
3315 
3316  $all = $result->fetchAll($fetchmode, $rekey, $force_array, $group);
3317  $result->free();
3318  return $all;
3319  }
3320 
3321  // }}}
3322 }
3323 
3324 // }}}
3325 // {{{ class MDB2_Result
3326 
3335 {
3336 }
3337 
3338 // }}}
3339 // {{{ class MDB2_Result_Common extends MDB2_Result
3340 require_once('./Services/Database/interfaces/interface.ilDBStatement.php');
3349 {
3350  // {{{ Variables (Properties)
3351 
3352  var $db;
3353  var $result;
3354  var $rownum = -1;
3355  var $types = array();
3356  var $values = array();
3357  var $offset;
3358  var $offset_count = 0;
3359  var $limit;
3361 
3362  // }}}
3363  // {{{ constructor: function __construct($db, $result, $limit = 0, $offset = 0)
3364 
3368  function __construct($db, $result, $limit = 0, $offset = 0)
3369  {
3370  $this->db = $db;
3371  $this->result = $result;
3372  $this->offset = $offset;
3373  $this->limit = max(0, $limit - 1);
3374  }
3375 
3376 
3377  public function fetch($fetch_mode = ilDBConstants::FETCHMODE_ASSOC) {
3378  return $this->fetchRow($fetch_mode);
3379  }
3380 
3381 
3382  public function fetchObject() {
3383  return $this->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
3384  }
3385 
3386 
3387  public function fetchAssoc() {
3388  return $this->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
3389  }
3390 
3391  // }}}
3392  // {{{ function MDB2_Result_Common($db, $result, $limit = 0, $offset = 0)
3393 
3397  function MDB2_Result_Common($db, $result, $limit = 0, $offset = 0)
3398  {
3399  $this->__construct($db, $result, $limit, $offset);
3400  }
3401 
3402  // }}}
3403  // {{{ function setResultTypes($types)
3404 
3426  function setResultTypes($types)
3427  {
3428  $load = $this->db->loadModule('Datatype', null, true);
3429  if (PEAR::isError($load)) {
3430  return $load;
3431  }
3432  $types = $this->db->datatype->checkResultTypes($types);
3433  if (PEAR::isError($types)) {
3434  return $types;
3435  }
3436  $this->types = $types;
3437  return MDB2_OK;
3438  }
3439 
3440  // }}}
3441  // {{{ function seek($rownum = 0)
3442 
3452  function seek($rownum = 0)
3453  {
3454  $target_rownum = $rownum - 1;
3455  if ($this->rownum > $target_rownum) {
3456  return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3457  'seeking to previous rows not implemented', __FUNCTION__);
3458  }
3459  while ($this->rownum < $target_rownum) {
3460  $this->fetchRow();
3461  }
3462  return MDB2_OK;
3463  }
3464 
3465  // }}}
3466  // {{{ function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
3467 
3478  function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
3479  {
3480  $err =& $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3481  'method not implemented', __FUNCTION__);
3482  return $err;
3483  }
3484 
3485  // }}}
3486  // {{{ function fetchOne($colnum = 0)
3487 
3498  function fetchOne($colnum = 0, $rownum = null)
3499  {
3500  $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
3501  $row = $this->fetchRow($fetchmode, $rownum);
3502  if (!is_array($row) || PEAR::isError($row)) {
3503  return $row;
3504  }
3505  if (!array_key_exists($colnum, $row)) {
3506  return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3507  'column is not defined in the result set: '.$colnum, __FUNCTION__);
3508  }
3509  return $row[$colnum];
3510  }
3511 
3512  // }}}
3513  // {{{ function fetchCol($colnum = 0)
3514 
3524  function fetchCol($colnum = 0)
3525  {
3526  $column = array();
3527  $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
3528  $row = $this->fetchRow($fetchmode);
3529  if (is_array($row)) {
3530  if (!array_key_exists($colnum, $row)) {
3531  return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3532  'column is not defined in the result set: '.$colnum, __FUNCTION__);
3533  }
3534  do {
3535  $column[] = $row[$colnum];
3536  } while (is_array($row = $this->fetchRow($fetchmode)));
3537  }
3538  if (PEAR::isError($row)) {
3539  return $row;
3540  }
3541  return $column;
3542  }
3543 
3544  // }}}
3545  // {{{ function fetchAll($fetchmode = MDB2_FETCHMODE_DEFAULT, $rekey = false, $force_array = false, $group = false)
3546 
3570  function fetchAll($fetchmode = MDB2_FETCHMODE_DEFAULT, $rekey = false,
3571  $force_array = false, $group = false)
3572  {
3573  $all = array();
3574  $row = $this->fetchRow($fetchmode);
3575  if (PEAR::isError($row)) {
3576  return $row;
3577  } elseif (!$row) {
3578  return $all;
3579  }
3580 
3581  $shift_array = $rekey ? false : null;
3582  if (!is_null($shift_array)) {
3583  if (is_object($row)) {
3584  $colnum = count(get_object_vars($row));
3585  } else {
3586  $colnum = count($row);
3587  }
3588  if ($colnum < 2) {
3589  return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3590  'rekey feature requires atleast 2 column', __FUNCTION__);
3591  }
3592  $shift_array = (!$force_array && $colnum == 2);
3593  }
3594 
3595  if ($rekey) {
3596  do {
3597  if (is_object($row)) {
3598  $arr = get_object_vars($row);
3599  $key = reset($arr);
3600  unset($row->{$key});
3601  } else {
3602  if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
3603  $key = reset($row);
3604  unset($row[key($row)]);
3605  } else {
3606  $key = array_shift($row);
3607  }
3608  if ($shift_array) {
3609  $row = array_shift($row);
3610  }
3611  }
3612  if ($group) {
3613  $all[$key][] = $row;
3614  } else {
3615  $all[$key] = $row;
3616  }
3617  } while (($row = $this->fetchRow($fetchmode)));
3618  } elseif ($fetchmode & MDB2_FETCHMODE_FLIPPED) {
3619  do {
3620  foreach ($row as $key => $val) {
3621  $all[$key][] = $val;
3622  }
3623  } while (($row = $this->fetchRow($fetchmode)));
3624  } else {
3625  do {
3626  $all[] = $row;
3627  } while (($row = $this->fetchRow($fetchmode)));
3628  }
3629 
3630  return $all;
3631  }
3632 
3633  // }}}
3634  // {{{ function rowCount()
3641  function rowCount()
3642  {
3643  return $this->rownum + 1;
3644  }
3645 
3646  // }}}
3647  // {{{ function numRows()
3648 
3656  function numRows()
3657  {
3658  return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3659  'method not implemented', __FUNCTION__);
3660  }
3661 
3662  // }}}
3663  // {{{ function nextResult()
3664 
3672  function nextResult()
3673  {
3674  return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3675  'method not implemented', __FUNCTION__);
3676  }
3677 
3678  // }}}
3679  // {{{ function getColumnNames()
3680 
3694  function getColumnNames($flip = false)
3695  {
3696  if (!isset($this->column_names)) {
3697  $result = $this->_getColumnNames();
3698  if (PEAR::isError($result)) {
3699  return $result;
3700  }
3701  $this->column_names = $result;
3702  }
3703  if ($flip) {
3704  return array_flip($this->column_names);
3705  }
3706  return $this->column_names;
3707  }
3708 
3709  // }}}
3710  // {{{ function _getColumnNames()
3711 
3722  function _getColumnNames()
3723  {
3724  return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3725  'method not implemented', __FUNCTION__);
3726  }
3727 
3728  // }}}
3729  // {{{ function numCols()
3730 
3739  function numCols()
3740  {
3741  return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3742  'method not implemented', __FUNCTION__);
3743  }
3744 
3745  // }}}
3746  // {{{ function getResource()
3747 
3755  function getResource()
3756  {
3757  return $this->result;
3758  }
3759 
3760  // }}}
3761  // {{{ function bindColumn($column, &$value, $type = null)
3762 
3774  function bindColumn($column, &$value, $type = null)
3775  {
3776  if (!is_numeric($column)) {
3777  $column_names = $this->getColumnNames();
3778  if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
3779  if ($this->db->options['field_case'] == CASE_LOWER) {
3780  $column = strtolower($column);
3781  } else {
3782  $column = strtoupper($column);
3783  }
3784  }
3785  $column = $column_names[$column];
3786  }
3787  $this->values[$column] =& $value;
3788  if (!is_null($type)) {
3789  $this->types[$column] = $type;
3790  }
3791  return MDB2_OK;
3792  }
3793 
3794  // }}}
3795  // {{{ function _assignBindColumns($row)
3796 
3807  {
3808  $row = array_values($row);
3809  foreach ($row as $column => $value) {
3810  if (array_key_exists($column, $this->values)) {
3811  $this->values[$column] = $value;
3812  }
3813  }
3814  return MDB2_OK;
3815  }
3816 
3817  // }}}
3818  // {{{ function free()
3819 
3827  function free()
3828  {
3829  $this->result = false;
3830  return MDB2_OK;
3831  }
3832 
3833  // }}}
3839  public function execute($a_data = null) {
3840  $res = $this->result->execute($a_data);
3841  if (MDB2::isError($res)) {
3842  throw new ilDatabaseException("There was an MDB2 error executing the prepared query: ".$this->result->getMessage());
3843  }
3844  return $res;
3845  }
3846 }
3847 
3848 // }}}
3849 // {{{ class MDB2_Row
3850 
3859 {
3860  // {{{ constructor: function __construct(&$row)
3861 
3867  function __construct(&$row)
3868  {
3869  foreach ($row as $key => $value) {
3870  $this->$key = &$row[$key];
3871  }
3872  }
3873 
3874  // }}}
3875  // {{{ function MDB2_Row(&$row)
3876 
3882  function MDB2_Row(&$row)
3883  {
3884  $this->__construct($row);
3885  }
3886 
3887  // }}}
3888 }
3889 
3890 // }}}
3891 // {{{ class MDB2_Statement_Common
3892 
3901 {
3902  // {{{ Variables (Properties)
3903 
3904  var $db;
3906  var $query;
3908  var $types;
3909  var $values = array();
3910  var $limit;
3911  var $offset;
3913 
3914  // }}}
3915  // {{{ constructor: function __construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
3916 
3920  function __construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
3921  {
3922  $this->db =& $db;
3923  $this->statement =& $statement;
3924  $this->positions = $positions;
3925  $this->query = $query;
3926  $this->types = (array)$types;
3927  $this->result_types = (array)$result_types;
3928  $this->limit = $limit;
3929  $this->is_manip = $is_manip;
3930  $this->offset = $offset;
3931  }
3932 
3933  // }}}
3934  // {{{ function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
3935 
3939  function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
3940  {
3941  $this->__construct($db, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
3942  }
3943 
3944  // }}}
3945  // {{{ function bindValue($parameter, &$value, $type = null)
3946 
3960  function bindValue($parameter, $value, $type = null)
3961  {
3962  if (!is_numeric($parameter)) {
3963  $parameter = preg_replace('/^:(.*)$/', '\\1', $parameter);
3964  }
3965  if (!in_array($parameter, $this->positions)) {
3966  return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
3967  'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
3968  }
3969  $this->values[$parameter] = $value;
3970  if (!is_null($type)) {
3971  $this->types[$parameter] = $type;
3972  }
3973  return MDB2_OK;
3974  }
3975 
3976  // }}}
3977  // {{{ function bindValueArray($values, $types = null)
3978 
3992  function bindValueArray($values, $types = null)
3993  {
3994  $types = is_array($types) ? array_values($types) : array_fill(0, count($values), null);
3995  $parameters = array_keys($values);
3996  foreach ($parameters as $key => $parameter) {
3997  $err = $this->bindValue($parameter, $values[$parameter], $types[$key]);
3998  if (PEAR::isError($err)) {
3999  return $err;
4000  }
4001  }
4002  return MDB2_OK;
4003  }
4004 
4005  // }}}
4006  // {{{ function bindParam($parameter, &$value, $type = null)
4007 
4021  function bindParam($parameter, &$value, $type = null)
4022  {
4023  if (!is_numeric($parameter)) {
4024  $parameter = preg_replace('/^:(.*)$/', '\\1', $parameter);
4025  }
4026  if (!in_array($parameter, $this->positions)) {
4027  return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
4028  'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
4029  }
4030  $this->values[$parameter] =& $value;
4031  if (!is_null($type)) {
4032  $this->types[$parameter] = $type;
4033  }
4034  return MDB2_OK;
4035  }
4036 
4037  // }}}
4038  // {{{ function bindParamArray(&$values, $types = null)
4039 
4053  function bindParamArray(&$values, $types = null)
4054  {
4055  $types = is_array($types) ? array_values($types) : array_fill(0, count($values), null);
4056  $parameters = array_keys($values);
4057  foreach ($parameters as $key => $parameter) {
4058  $err = $this->bindParam($parameter, $values[$parameter], $types[$key]);
4059  if (PEAR::isError($err)) {
4060  return $err;
4061  }
4062  }
4063  return MDB2_OK;
4064  }
4065 
4066  // }}}
4067  // {{{ function &execute($values = null, $result_class = true, $result_wrap_class = false)
4068 
4082  function &execute($values = null, $result_class = true, $result_wrap_class = false)
4083  {
4084  if (is_null($this->positions)) {
4085  return $this->db->raiseError(MDB2_ERROR, null, null,
4086  'Prepared statement has already been freed', __FUNCTION__);
4087  }
4088 
4089  $values = (array)$values;
4090  if (!empty($values)) {
4091  $err = $this->bindValueArray($values);
4092  if (PEAR::isError($err)) {
4093  return $this->db->raiseError(MDB2_ERROR, null, null,
4094  'Binding Values failed with message: ' . $err->getMessage(), __FUNCTION__);
4095  }
4096  }
4097  $result =& $this->_execute($result_class, $result_wrap_class);
4098  return $result;
4099  }
4100 
4101  // }}}
4102  // {{{ function &_execute($result_class = true, $result_wrap_class = false)
4103 
4114  function &_execute($result_class = true, $result_wrap_class = false)
4115  {
4116  $this->last_query = $this->query;
4117  $query = '';
4118  $last_position = 0;
4119  foreach ($this->positions as $current_position => $parameter) {
4120  if (!array_key_exists($parameter, $this->values)) {
4121  return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
4122  'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
4123  }
4124  $value = $this->values[$parameter];
4125  $query.= substr($this->query, $last_position, $current_position - $last_position);
4126  if (!isset($value)) {
4127  $value_quoted = 'NULL';
4128  } else {
4129  $type = !empty($this->types[$parameter]) ? $this->types[$parameter] : null;
4130  $value_quoted = $this->db->quote($value, $type);
4131  if (PEAR::isError($value_quoted)) {
4132  return $value_quoted;
4133  }
4134  }
4135  $query.= $value_quoted;
4136  $last_position = $current_position + 1;
4137  }
4138  $query.= substr($this->query, $last_position);
4139 
4140  $this->db->offset = $this->offset;
4141  $this->db->limit = $this->limit;
4142  if ($this->is_manip) {
4143  $result = $this->db->exec($query);
4144  } else {
4145  $result =& $this->db->query($query, $this->result_types, $result_class, $result_wrap_class);
4146  }
4147  return $result;
4148  }
4149 
4150  // }}}
4151  // {{{ function free()
4152 
4160  function free()
4161  {
4162  if (is_null($this->positions)) {
4163  return $this->db->raiseError(MDB2_ERROR, null, null,
4164  'Prepared statement has already been freed', __FUNCTION__);
4165  }
4166 
4167  $this->statement = null;
4168  $this->positions = null;
4169  $this->query = null;
4170  $this->types = null;
4171  $this->result_types = null;
4172  $this->limit = null;
4173  $this->is_manip = null;
4174  $this->offset = null;
4175  $this->values = null;
4176 
4177  return MDB2_OK;
4178  }
4179 
4180  // }}}
4181 }
4182 
4183 // }}}
4184 // {{{ class MDB2_Module_Common
4185 
4194 {
4195  // {{{ Variables (Properties)
4196 
4205 
4206  // }}}
4207  // {{{ constructor: function __construct($db_index)
4208 
4212  function __construct($db_index)
4213  {
4214  $this->db_index = $db_index;
4215  }
4216 
4217  // }}}
4218  // {{{ function MDB2_Module_Common($db_index)
4219 
4223  function MDB2_Module_Common($db_index)
4224  {
4225  $this->__construct($db_index);
4226  }
4227 
4228  // }}}
4229  // {{{ function &getDBInstance()
4230 
4238  function &getDBInstance()
4239  {
4240  if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
4241  $result =& $GLOBALS['_MDB2_databases'][$this->db_index];
4242  } else {
4244  'could not find MDB2 instance');
4245  }
4246  return $result;
4247  }
4248 
4249  // }}}
4250 }
4251 
4252 // }}}
4253 // {{{ function MDB2_closeOpenTransactions()
4254 
4264 {
4265  reset($GLOBALS['_MDB2_databases']);
4266  while (next($GLOBALS['_MDB2_databases'])) {
4267  $key = key($GLOBALS['_MDB2_databases']);
4268  if ($GLOBALS['_MDB2_databases'][$key]->opened_persistent
4269  && $GLOBALS['_MDB2_databases'][$key]->in_transaction
4270  ) {
4271  $GLOBALS['_MDB2_databases'][$key]->rollback();
4272  }
4273  }
4274 }
4275 
4276 // }}}
4277 // {{{ function MDB2_defaultDebugOutput(&$db, $scope, $message, $is_manip = null)
4278 
4295 function MDB2_defaultDebugOutput(&$db, $scope, $message, $context = array())
4296 {
4297  $db->debug_output.= $scope.'('.$db->db_index.'): ';
4298  $db->debug_output.= $message.$db->getOption('log_line_break');
4299  return $message;
4300 }
4301 
4302 // }}}
4303 ?>
setDSN($dsn)
set the DSN
Definition: MDB2.php:2300
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
Definition: MDB2.php:134
fetch($fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
Definition: MDB2.php:3377
getOption($option)
Returns the value of an option.
Definition: MDB2.php:1561
$error
Definition: Error.php:17
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these...
Definition: MDB2.php:72
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
Definition: MDB2.php:3478
nextID($seq_name, $ondemand=true)
Returns the next free id of a sequence.
Definition: MDB2.php:3144
bindColumn($column, &$value, $type=null)
Set bind variable to a column.
Definition: MDB2.php:3774
const MDB2_ERROR_CANNOT_REPLACE
Definition: MDB2.php:100
getResource()
return the resource associated with the result object
Definition: MDB2.php:3755
MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip=false, $limit=null, $offset=null)
PHP 4 Constructor.
Definition: MDB2.php:3939
beginTransaction($savepoint=null)
Start a transaction or set a savepoint.
Definition: MDB2.php:1955
_affectedRows($connection, $result=null)
Returns the number of rows affected.
Definition: MDB2.php:2452
getIndexName($idx)
adds index name formatting to a index name
Definition: MDB2.php:3125
loadFile($file)
load a file (like &#39;Date&#39;)
Definition: MDB2.php:521
MDB2_Driver_Common()
PHP 4 Constructor.
Definition: MDB2.php:1315
isResult($value)
Tell whether a value is a MDB2 result.
Definition: MDB2.php:643
setTransactionIsolation($isolation, $options=array())
Set the transacton isolation level.
Definition: MDB2.php:2045
const MDB2_FETCHMODE_DEFAULT
This is a special constant that tells MDB2 the user hasn&#39;t specified any particular get mode...
Definition: MDB2.php:124
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
const MDB2_ERROR_INVALID
Definition: MDB2.php:80
$result
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78
supports($feature)
Tell whether a DB implementation or its backend extension supports a given feature.
Definition: MDB2.php:3086
const MDB2_ERROR_NOSUCHDB
Definition: MDB2.php:98
bindValue($parameter, $value, $type=null)
Set the value of a parameter of a prepared query.
Definition: MDB2.php:3960
while(false !==( $line=fgets( $in))) if(! $columns) $ignore
Definition: Utf8Test.php:63
Several methods to convert the MDB2 native timestamp format (ISO based) to and from data structures t...
setLimit($limit, $offset=null)
set the range of the next query
Definition: MDB2.php:2636
const MDB2_ERROR_CANNOT_DROP
Definition: MDB2.php:89
$GLOBALS['_MDB2_databases']
These are global variables that are used to track the various class instances.
Definition: MDB2.php:224
__construct($code=MDB2_ERROR, $mode=PEAR_ERROR_RETURN, $level=E_USER_NOTICE, $debuginfo=null)
MDB2_Error constructor.
Definition: MDB2.php:971
const MDB2_PORTABILITY_EMPTY_TO_NULL
Portability: convert empty values to null strings in data output by query*() and fetch*().
Definition: MDB2.php:203
const MDB2_ERROR_NOT_CAPABLE
Definition: MDB2.php:81
$code
Definition: example_050.php:99
const MDB2_ERROR_CANNOT_ALTER
Definition: MDB2.php:103
const MDB2_ERROR_CANNOT_DELETE
Definition: MDB2.php:88
__toString()
String conversation.
Definition: MDB2.php:1359
bindValueArray($values, $types=null)
Set the values of multiple a parameter of a prepared query in bulk.
Definition: MDB2.php:3992
disconnect($force=true)
Log out and disconnect from the database.
Definition: MDB2.php:2241
const MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES
Portability: removes database/table qualifiers from associative indexes.
Definition: MDB2.php:209
fetchAll($fetchmode=MDB2_FETCHMODE_DEFAULT, $rekey=false, $force_array=false, $group=false)
Fetch and return all rows from the current row pointer position.
Definition: MDB2.php:3570
free()
Free the internal references so that the instance can be destroyed.
Definition: MDB2.php:1342
bindParamArray(&$values, $types=null)
Bind the variables of multiple a parameter of a prepared query in bulk.
Definition: MDB2.php:4053
execute($a_data=null)
Definition: MDB2.php:3839
connect()
Connect to the database.
Definition: MDB2.php:2204
fetchCol($colnum=0)
Fetch and return a column from the current row pointer position.
Definition: MDB2.php:3524
& exec($query)
Execute a manipulation query to the database and return the number of affected rows.
Definition: MDB2.php:2470
apiVersion()
Return the MDB2 API version.
Definition: MDB2.php:545
const MDB2_FETCHMODE_FLIPPED
For multi-dimensional results: normally the first level of arrays is the row number, and the second level indexed by column number or name.
Definition: MDB2.php:147
numCols()
Count the number of columns returned by the DBMS in a query result.
Definition: MDB2.php:3739
quoteIdentifier($str, $check_option=false)
Quote a string so it can be safely used as a table or column name.
Definition: MDB2.php:1705
Class ilDatabaseException.
beginNestedTransaction()
Start a nested transaction.
Definition: MDB2.php:2068
setDatabase($name)
Select a different database.
Definition: MDB2.php:2265
const MDB2_ERROR_SYNTAX
Definition: MDB2.php:74
numRows()
Returns the number of rows in a result object.
Definition: MDB2.php:3656
_assignBindColumns($row)
Bind a variable to a value in the result row.
Definition: MDB2.php:3806
compareDefinition($current, $previous)
Obtain an array of changes that may need to applied.
Definition: MDB2.php:3062
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: MDB2.php:2424
rowCount()
Returns the actual row number that was last fetched (count from 0)
Definition: MDB2.php:3641
const MDB2_ERROR_CONSTRAINT
Definition: MDB2.php:75
commit($savepoint=null)
Commit the database changes done during a transaction that is in progress or release a savepoint...
Definition: MDB2.php:1976
__construct($db, $result, $limit=0, $offset=0)
Constructor.
Definition: MDB2.php:3368
getSequenceName($sqn)
adds sequence name formatting to a sequence name
Definition: MDB2.php:3107
_getColumnNames()
Retrieve the names of columns returned by the DBMS in a query result.
Definition: MDB2.php:3722
free()
Release resources allocated for the specified prepared query.
Definition: MDB2.php:4160
getDebugOutput()
output debug info
Definition: MDB2.php:1611
const MDB2_ERROR_INVALID_DATE
Definition: MDB2.php:84
MDB2_closeOpenTransactions()
Close any open transactions form persistent connections.
Definition: MDB2.php:4263
escape($text, $escape_wildcards=false)
Quotes a string so it can be safely used in a query.
Definition: MDB2.php:1630
& prepare($query, $types=null, $result_types=null, $lobs=array())
Prepares a query for multiple execution with execute().
Definition: MDB2.php:2860
_modifyQuery($query, $is_manip, $limit, $offset)
Changes a query string for various DBMS specific reasons.
Definition: MDB2.php:2405
const MDB2_ERROR_INVALID_DSN
Definition: MDB2.php:95
MDB2_Result_Common($db, $result, $limit=0, $offset=0)
PHP 4 Constructor.
Definition: MDB2.php:3397
const MDB2_ERROR_NOSUCHFIELD
Definition: MDB2.php:91
& query($query, $types=null, $result_class=true, $result_wrap_class=false)
Send a query to the database and return any results.
Definition: MDB2.php:2507
const MDB2_FETCHMODE_OBJECT
Column data as object properties.
Definition: MDB2.php:139
$info
Definition: example_052.php:80
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1587
& _wrapResult($result, $types=array(), $result_class=true, $result_wrap_class=false, $limit=null, $offset=null)
wrap a result set into the correct class
Definition: MDB2.php:2546
_skipDelimitedStrings($query, $position, $p_position)
Utility method, used by prepare() to avoid replacing placeholders within delimited strings...
Definition: MDB2.php:2968
MDB2_Module_Common($db_index)
PHP 4 Constructor.
Definition: MDB2.php:4223
const MDB2_FETCHMODE_ORDERED
Column data indexed by numbers, ordered from 0 and up.
Definition: MDB2.php:129
__construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip=false, $limit=null, $offset=null)
Constructor.
Definition: MDB2.php:3920
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:114
$column
Definition: 39dropdown.php:62
& standaloneQuery($query, $types=null, $is_manip=false)
execute a query as database administrator
Definition: MDB2.php:2365
if(!is_array($argv)) $options
failNestedTransaction($error=null, $immediately=false)
Force setting nested transaction to failed.
Definition: MDB2.php:2161
replace($table, $fields)
Execute a SQL REPLACE query.
Definition: MDB2.php:2765
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
Definition: MDB2.php:436
& factory($dsn, $options=false)
Create a new MDB2 object for the specified database type.
Definition: MDB2.php:379
const MDB2_ERROR_NEED_MORE_DATA
Definition: MDB2.php:92
getNestedTransactionError()
The first error that occured since the transaction start.
Definition: MDB2.php:2191
const MDB2_PORTABILITY_RTRIM
Portability: right trim the data output by query*() and fetch*().
Definition: MDB2.php:169
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
Definition: MDB2.php:660
setOption($option, $value)
set the option for the db class
Definition: MDB2.php:1539
setResultTypes($types)
Define the list of types to be associated with the columns of a given result set. ...
Definition: MDB2.php:3426
isStatement($value)
Tell whether a value is a MDB2 statement interface.
Definition: MDB2.php:677
const MDB2_PORTABILITY_ALL
Portability: turn on all portability features.
Definition: MDB2.php:215
loadClass($class_name, $debug)
Loads a PEAR class.
Definition: MDB2.php:330
parseDSN($dsn)
Definition: MDB2.php:796
const PEAR_ERROR_RETURN
#+ ERROR constants
Definition: PEAR.php:31
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:76
completeNestedTransaction($force_rollback=false)
Finish a nested transaction by rolling back if an error occured or committing otherwise.
Definition: MDB2.php:2104
classExists($classname)
Checks if a class exists without triggering __autoload.
Definition: MDB2.php:309
lastInsertID($table=null, $field=null)
Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $tab...
Definition: MDB2.php:3164
seek($rownum=0)
Seek to a specific row in a result set.
Definition: MDB2.php:3452
const MDB2_ERROR_NOT_LOCKED
Definition: MDB2.php:93
& raiseError($code=null, $mode=null, $options=null, $userinfo=null, $method=null)
This method is used to communicate an error and invoke error callbacks etc.
Definition: MDB2.php:1412
const MDB2_ERROR_CONNECT_FAILED
Definition: MDB2.php:96
& _execute($result_class=true, $result_wrap_class=false)
Execute a prepared query statement helper method.
Definition: MDB2.php:4114
inTransaction($ignore_nested=false)
If a transaction is currently open.
Definition: MDB2.php:2018
const MDB2_ERROR_CONSTRAINT_NOT_NULL
Definition: MDB2.php:101
_fixResultArrayValues(&$row, $mode)
Do all necessary conversions on result arrays to fix DBMS quirks.
Definition: MDB2.php:1760
queryAll($query, $types=null, $fetchmode=MDB2_FETCHMODE_DEFAULT, $rekey=false, $force_array=false, $group=false)
Execute the specified query, fetch all the rows of the result set into a two dimensional array and th...
Definition: MDB2.php:3308
currID($seq_name)
Returns the current id of a sequence.
Definition: MDB2.php:3182
const MDB2_ERROR
Definition: MDB2.php:73
Create styles array
The data for the language used.
const MDB2_ERROR_CANNOT_CREATE
Definition: MDB2.php:87
getDatabase()
Get the current database.
Definition: MDB2.php:2283
isConnection($value)
Tell whether a value is a MDB2 connection.
Definition: MDB2.php:626
const MDB2_ERROR_MISMATCH
Definition: MDB2.php:79
& singleton($dsn=null, $options=false)
Returns a MDB2 connection with the requested DSN.
Definition: MDB2.php:486
__call($method, $params)
Calls a module method using the __call magic method.
Definition: MDB2.php:1914
const MDB2_ERROR_VALUE_COUNT_ON_ROW
Definition: MDB2.php:94
nextResult()
Move the internal result pointer to the next available result.
Definition: MDB2.php:3672
bindParam($parameter, &$value, $type=null)
Bind a variable to a parameter of a prepared query.
Definition: MDB2.php:4021
__construct(&$row)
constructor
Definition: MDB2.php:3867
fetchOne($colnum=0, $rownum=null)
fetch single column from the next row from a result set
Definition: MDB2.php:3498
escapePattern($text)
Quotes pattern (% and _) characters in a string)
Definition: MDB2.php:1657
& execute($values=null, $result_class=true, $result_wrap_class=false)
Execute a prepared query statement.
Definition: MDB2.php:4082
const MDB2_ERROR_INVALID_NUMBER
Definition: MDB2.php:83
const MDB2_ERROR_EXTENSION_NOT_FOUND
Definition: MDB2.php:97
getConnection()
Returns a native connection.
Definition: MDB2.php:1738
& raiseError($code=null, $mode=null, $options=null, $userinfo=null)
This method is used to communicate an error and invoke error callbacks etc.
Definition: MDB2.php:577
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:522
__construct($db_index)
Constructor.
Definition: MDB2.php:4212
quote($value, $type=null, $quote=true, $escape_wildcards=false)
Convert a text value into a DBMS specific format that is suitable to compose query statements...
Definition: MDB2.php:3014
queryRow($query, $types=null, $fetchmode=MDB2_FETCHMODE_DEFAULT)
Execute the specified query, fetch the values from the first row of the result set into an array and ...
Definition: MDB2.php:3239
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
queryOne($query, $type=null, $colnum=0)
Execute the specified query, fetch the value from the first column of the first row of the result set...
Definition: MDB2.php:3208
const MDB2_ERROR_NODBSELECTED
Definition: MDB2.php:86
const MDB2_ERROR_DEADLOCK
Definition: MDB2.php:102
const MDB2_ERROR_TRUNCATED
Definition: MDB2.php:82
$text
getDSN($type='string', $hidepw=false)
return the DSN as a string
Definition: MDB2.php:2325
setOptions(&$db, $options)
set option array in an exiting database object
Definition: MDB2.php:284
queryCol($query, $type=null, $colnum=0)
Execute the specified query, fetch the value from the first column of each row of the result set into...
Definition: MDB2.php:3269
rollback($savepoint=null)
Cancel any database changes done during a transaction or since a specific savepoint that is in progre...
Definition: MDB2.php:1997
errorMessage($value=null)
Return a textual error message for a MDB2 error code.
Definition: MDB2.php:697
MDB2_defaultDebugOutput(&$db, $scope, $message, $context=array())
default debug output handler
Definition: MDB2.php:4295
const MDB2_ERROR_LOADMODULE
Definition: MDB2.php:106
fileExists($file)
Checks if a file exists in the include path.
Definition: MDB2.php:926
const MDB2_ERROR_ACCESS_VIOLATION
Definition: MDB2.php:99
setCharset($charset, $connection=null)
Set the charset on the current connection.
Definition: MDB2.php:2221
resetWarnings()
reset the warning array
Definition: MDB2.php:1465
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
MDB2_Row(&$row)
PHP 4 Constructor.
Definition: MDB2.php:3882
getServerVersion($native=false)
return version information about the server
Definition: MDB2.php:2617
errorInfo($error=null)
This method is used to collect information about an error.
Definition: MDB2.php:1381
__destruct()
Destructor.
Definition: MDB2.php:1327
const MDB2_ERROR_DIVZERO
Definition: MDB2.php:85
getColumnNames($flip=false)
Retrieve the names of columns returned by the DBMS in a query result or from the cache.
Definition: MDB2.php:3694
free()
Free the internal resources associated with result.
Definition: MDB2.php:3827
$params
Definition: example_049.php:96
& loadModule($module, $property=null, $phptype_specific=null)
loads a module
Definition: MDB2.php:1845
Interface ilDBStatement.
getDeclaration($type, $name, $field)
Obtain DBMS specific SQL code portion needed to declare of the given type.
Definition: MDB2.php:3040
const MDB2_ERROR_ALREADY_EXISTS
Definition: MDB2.php:77
const MDB2_PORTABILITY_FIX_CASE
Portability: convert names of tables and fields to case defined in the "field_case" option when using...
Definition: MDB2.php:163
__construct()
Constructor.
Definition: MDB2.php:1301
$test
Definition: Utf8Test.php:84
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
getAsKeyword()
Gets the string to alias column.
Definition: MDB2.php:1722
subSelect($query, $type=false)
simple subselect emulation: leaves the query untouched for all RDBMS that support subselects ...
Definition: MDB2.php:2674
setFetchMode($fetchmode, $object_class='stdClass')
Sets which fetch mode should be used by default on queries on this connection.
Definition: MDB2.php:1509
getWarnings()
Get all warnings in reverse order.
Definition: MDB2.php:1482
const MDB2_ERROR_NOSUCHTABLE
Definition: MDB2.php:90
$insert