ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
56set_include_path("./Services/Database/lib/PEAR" . PATH_SEPARATOR . ini_get('include_path'));
57if (!class_exists('PEAR')) {
58 require_once 'PEAR.php';
59}
60// END PATCH
61
62// {{{ Error constants
63
72define('MDB2_OK', true);
73define('MDB2_ERROR', -1);
74define('MDB2_ERROR_SYNTAX', -2);
75define('MDB2_ERROR_CONSTRAINT', -3);
76define('MDB2_ERROR_NOT_FOUND', -4);
77define('MDB2_ERROR_ALREADY_EXISTS', -5);
78define('MDB2_ERROR_UNSUPPORTED', -6);
79define('MDB2_ERROR_MISMATCH', -7);
80define('MDB2_ERROR_INVALID', -8);
81define('MDB2_ERROR_NOT_CAPABLE', -9);
82define('MDB2_ERROR_TRUNCATED', -10);
83define('MDB2_ERROR_INVALID_NUMBER', -11);
84define('MDB2_ERROR_INVALID_DATE', -12);
85define('MDB2_ERROR_DIVZERO', -13);
86define('MDB2_ERROR_NODBSELECTED', -14);
87define('MDB2_ERROR_CANNOT_CREATE', -15);
88define('MDB2_ERROR_CANNOT_DELETE', -16);
89define('MDB2_ERROR_CANNOT_DROP', -17);
90define('MDB2_ERROR_NOSUCHTABLE', -18);
91define('MDB2_ERROR_NOSUCHFIELD', -19);
92define('MDB2_ERROR_NEED_MORE_DATA', -20);
93define('MDB2_ERROR_NOT_LOCKED', -21);
94define('MDB2_ERROR_VALUE_COUNT_ON_ROW', -22);
95define('MDB2_ERROR_INVALID_DSN', -23);
96define('MDB2_ERROR_CONNECT_FAILED', -24);
97define('MDB2_ERROR_EXTENSION_NOT_FOUND',-25);
98define('MDB2_ERROR_NOSUCHDB', -26);
99define('MDB2_ERROR_ACCESS_VIOLATION', -27);
100define('MDB2_ERROR_CANNOT_REPLACE', -28);
101define('MDB2_ERROR_CONSTRAINT_NOT_NULL',-29);
102define('MDB2_ERROR_DEADLOCK', -30);
103define('MDB2_ERROR_CANNOT_ALTER', -31);
104define('MDB2_ERROR_MANAGER', -32);
105define('MDB2_ERROR_MANAGER_PARSE', -33);
106define('MDB2_ERROR_LOADMODULE', -34);
107define('MDB2_ERROR_INSUFFICIENT_DATA', -35);
108// }}}
109// {{{ Verbose constants
114define('MDB2_PREPARE_MANIP', false);
115define('MDB2_PREPARE_RESULT', null);
116
117// }}}
118// {{{ Fetchmode constants
119
124define('MDB2_FETCHMODE_DEFAULT', 0);
125
129define('MDB2_FETCHMODE_ORDERED', 1);
130
134define('MDB2_FETCHMODE_ASSOC', 2);
135
139define('MDB2_FETCHMODE_OBJECT', 3);
140
147define('MDB2_FETCHMODE_FLIPPED', 4);
148
149// }}}
150// {{{ Portability mode constants
151
156define('MDB2_PORTABILITY_NONE', 0);
157
163define('MDB2_PORTABILITY_FIX_CASE', 1);
164
169define('MDB2_PORTABILITY_RTRIM', 2);
170
175define('MDB2_PORTABILITY_DELETE_COUNT', 4);
176
181define('MDB2_PORTABILITY_NUMROWS', 8);
182
196define('MDB2_PORTABILITY_ERRORS', 16);
197
203define('MDB2_PORTABILITY_EMPTY_TO_NULL', 32);
204
209define('MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES', 64);
210
215define('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
270class 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
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
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)) {
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
1025
1032
1039
1046
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
1127 var $options = array(
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
1217
1223 var $in_transaction = false;
1224
1231
1238
1244 var $offset = 0;
1245
1251 var $limit = 0;
1252
1259
1266
1273
1280
1286 var $modules = array();
1287
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($message = null,
1413 $code = null,
1414 $mode = null,
1415 $options = null,
1416 $userinfo = null,
1417 $error_class = null,
1418 $skipmsg = false)
1419 {
1420 $userinfo = "[Error message: $userinfo]\n";
1421 // The error is yet a MDB2 error object
1422 if (PEAR::isError($code)) {
1423 // because we use the static PEAR::raiseError, our global
1424 // handler should be used if it is set
1425 if (is_null($mode) && !empty($this->_default_error_mode)) {
1428 }
1429 if (is_null($userinfo)) {
1430 $userinfo = $code->getUserinfo();
1431 }
1432 $code = $code->getCode();
1433 } elseif ($code == MDB2_ERROR_NOT_FOUND) {
1434 // extension not loaded: don't call $this->errorInfo() or the script
1435 // will die
1436 } elseif (isset($this->connection)) {
1437 if (!empty($this->last_query)) {
1438 $userinfo.= "[Last executed query: {$this->last_query}]\n";
1439 }
1440 $native_errno = $native_msg = null;
1441 list($code, $native_errno, $native_msg) = $this->errorInfo($code);
1442 if (!is_null($native_errno) && $native_errno !== '') {
1443 $userinfo.= "[Native code: $native_errno]\n";
1444 }
1445 if (!is_null($native_msg) && $native_msg !== '') {
1446 $userinfo.= "[Native message: ". strip_tags($native_msg) ."]\n";
1447 }
1448 if (!is_null($method)) {
1449 $userinfo = $method.': '.$userinfo;
1450 }
1451 }
1452
1453 $err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
1454 if ($err->getMode() !== PEAR_ERROR_RETURN
1455 && isset($this->nested_transaction_counter) && !$this->has_transaction_error) {
1456 $this->has_transaction_error =& $err;
1457 }
1458 return $err;
1459 }
1460
1461 // }}}
1462 // {{{ function resetWarnings()
1463
1471 function resetWarnings()
1472 {
1473 $this->warnings = array();
1474 }
1475
1476 // }}}
1477 // {{{ function getWarnings()
1478
1488 function getWarnings()
1489 {
1490 return array_reverse($this->warnings);
1491 }
1492
1493 // }}}
1494 // {{{ function setFetchMode($fetchmode, $object_class = 'stdClass')
1495
1515 function setFetchMode($fetchmode, $object_class = 'stdClass')
1516 {
1517 switch ($fetchmode) {
1519 $this->options['fetch_class'] = $object_class;
1522 $this->fetchmode = $fetchmode;
1523 break;
1524 default:
1525 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1526 'invalid fetchmode mode', __FUNCTION__);
1527 }
1528
1529 return MDB2_OK;
1530 }
1531
1532 // }}}
1533 // {{{ function setOption($option, $value)
1534
1545 function setOption($option, $value)
1546 {
1547 if (array_key_exists($option, $this->options)) {
1548 $this->options[$option] = $value;
1549 return MDB2_OK;
1550 }
1551 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1552 "unknown option $option", __FUNCTION__);
1553 }
1554
1555 // }}}
1556 // {{{ function getOption($option)
1557
1567 function getOption($option)
1568 {
1569 if (array_key_exists($option, $this->options)) {
1570 return $this->options[$option];
1571 }
1572 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1573 "unknown option $option", __FUNCTION__);
1574 }
1575
1576 // }}}
1577 // {{{ function debug($message, $scope = '', $is_manip = null)
1578
1593 function debug($message, $scope = '', $context = array())
1594 {
1595 if ($this->options['debug'] && $this->options['debug_handler']) {
1596 if (!$this->options['debug_expanded_output']) {
1597 if (!empty($context['when']) && $context['when'] !== 'pre') {
1598 return null;
1599 }
1600 $context = empty($context['is_manip']) ? false : $context['is_manip'];
1601 }
1602 return call_user_func_array($this->options['debug_handler'], array(&$this, $scope, $message, $context));
1603 }
1604 return null;
1605 }
1606
1607 // }}}
1608 // {{{ function getDebugOutput()
1609
1618 {
1619 return $this->debug_output;
1620 }
1621
1622 // }}}
1623 // {{{ function escape($text)
1624
1636 function escape($text, $escape_wildcards = false)
1637 {
1638 if ($escape_wildcards) {
1639 $text = $this->escapePattern($text);
1640 }
1641
1642 $text = str_replace($this->string_quoting['end'], $this->string_quoting['escape'] . $this->string_quoting['end'], $text);
1643 return $text;
1644 }
1645
1646 // }}}
1647 // {{{ function escapePattern($text)
1648
1664 {
1665 if ($this->string_quoting['escape_pattern']) {
1666 $text = str_replace($this->string_quoting['escape_pattern'], $this->string_quoting['escape_pattern'] . $this->string_quoting['escape_pattern'], $text);
1667 foreach ($this->wildcards as $wildcard) {
1668 $text = str_replace($wildcard, $this->string_quoting['escape_pattern'] . $wildcard, $text);
1669 }
1670 }
1671 return $text;
1672 }
1673
1674 // }}}
1675 // {{{ function quoteIdentifier($str, $check_option = false)
1676
1711 function quoteIdentifier($str, $check_option = false)
1712 {
1713 if ($check_option && !$this->options['quote_identifier']) {
1714 return $str;
1715 }
1716 $str = str_replace($this->identifier_quoting['end'], $this->identifier_quoting['escape'] . $this->identifier_quoting['end'], $str);
1717 return $this->identifier_quoting['start'] . $str . $this->identifier_quoting['end'];
1718 }
1719
1720 // }}}
1721 // {{{ function getAsKeyword()
1722
1728 function getAsKeyword()
1729 {
1730 return $this->as_keyword;
1731 }
1732
1733 // }}}
1734 // {{{ function getConnection()
1735
1744 function getConnection()
1745 {
1746 $result = $this->connect();
1747 if (PEAR::isError($result)) {
1748 return $result;
1749 }
1750 return $this->connection;
1751 }
1752
1753 // }}}
1754 // {{{ function _fixResultArrayValues(&$row, $mode)
1755
1766 function _fixResultArrayValues(&$row, $mode)
1767 {
1768 switch ($mode) {
1770 foreach ($row as $key => $value) {
1771 if ($value === '') {
1772 $row[$key] = null;
1773 }
1774 }
1775 break;
1777 foreach ($row as $key => $value) {
1778 if (is_string($value)) {
1779 $row[$key] = rtrim($value);
1780 }
1781 }
1782 break;
1784 $tmp_row = array();
1785 foreach ($row as $key => $value) {
1786 $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1787 }
1788 $row = $tmp_row;
1789 break;
1791 foreach ($row as $key => $value) {
1792 if ($value === '') {
1793 $row[$key] = null;
1794 } elseif (is_string($value)) {
1795 $row[$key] = rtrim($value);
1796 }
1797 }
1798 break;
1800 $tmp_row = array();
1801 foreach ($row as $key => $value) {
1802 if (is_string($value)) {
1803 $value = rtrim($value);
1804 }
1805 $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1806 }
1807 $row = $tmp_row;
1808 break;
1810 $tmp_row = array();
1811 foreach ($row as $key => $value) {
1812 if ($value === '') {
1813 $value = null;
1814 }
1815 $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1816 }
1817 $row = $tmp_row;
1818 break;
1820 $tmp_row = array();
1821 foreach ($row as $key => $value) {
1822 if ($value === '') {
1823 $value = null;
1824 } elseif (is_string($value)) {
1825 $value = rtrim($value);
1826 }
1827 $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value;
1828 }
1829 $row = $tmp_row;
1830 break;
1831 }
1832 }
1833
1834 // }}}
1835 // {{{ function &loadModule($module, $property = null, $phptype_specific = null)
1836
1851 function &loadModule($module, $property = null, $phptype_specific = null)
1852 {
1853 if (!$property) {
1854 $property = strtolower($module);
1855 }
1856
1857 if (!isset($this->{$property})) {
1858 $version = $phptype_specific;
1859 if ($phptype_specific !== false) {
1860 $version = true;
1861 $class_name = 'MDB2_Driver_'.$module.'_'.$this->phptype;
1862 $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php';
1863 }
1864 if ($phptype_specific === false
1865 || (!MDB2::classExists($class_name) && !MDB2::fileExists($file_name))
1866 ) {
1867 $version = false;
1868 $class_name = 'MDB2_'.$module;
1869 $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php';
1870 }
1871
1872 $err = MDB2::loadClass($class_name, $this->getOption('debug'));
1873 if (PEAR::isError($err)) {
1874 return $err;
1875 }
1876
1877 // load modul in a specific version
1878 if ($version) {
1879 if (method_exists($class_name, 'getClassName')) {
1880 $class_name_new = call_user_func(array($class_name, 'getClassName'), $this->db_index);
1881 if ($class_name != $class_name_new) {
1882 $class_name = $class_name_new;
1883 $err = MDB2::loadClass($class_name, $this->getOption('debug'));
1884 if (PEAR::isError($err)) {
1885 return $err;
1886 }
1887 }
1888 }
1889 }
1890
1891 if (!MDB2::classExists($class_name)) {
1892 $err =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null,
1893 "unable to load module '$module' into property '$property'", __FUNCTION__);
1894 return $err;
1895 }
1896 $this->{$property} = new $class_name($this->db_index);
1897 $this->modules[$module] =& $this->{$property};
1898 if ($version) {
1899 // this will be used in the connect method to determine if the module
1900 // needs to be loaded with a different version if the server
1901 // version changed in between connects
1902 $this->loaded_version_modules[] = $property;
1903 }
1904 }
1905
1906 return $this->{$property};
1907 }
1908
1909 // }}}
1910 // {{{ function __call($method, $params)
1911
1920 function __call($method, $params)
1921 {
1922 $module = null;
1923 if (preg_match('/^([a-z]+)([A-Z])(.*)$/', $method, $match)
1924 && isset($this->options['modules'][$match[1]])
1925 ) {
1926 $module = $this->options['modules'][$match[1]];
1927 $method = strtolower($match[2]).$match[3];
1928 if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) {
1929 $result =& $this->loadModule($module);
1930 if (PEAR::isError($result)) {
1931 return $result;
1932 }
1933 }
1934 } else {
1935 foreach ($this->modules as $key => $foo) {
1936 if (is_object($this->modules[$key])
1937 && method_exists($this->modules[$key], $method)
1938 ) {
1939 $module = $key;
1940 break;
1941 }
1942 }
1943 }
1944 if (!is_null($module)) {
1945 return call_user_func_array(array(&$this->modules[$module], $method), $params);
1946 }
1947 trigger_error(sprintf('Call to undefined function: %s::%s().', get_class($this), $method), E_USER_ERROR);
1948 }
1949
1950 // }}}
1951 // {{{ function beginTransaction($savepoint = null)
1952
1961 function beginTransaction($savepoint = null)
1962 {
1963 $this->debug('Starting transaction', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
1964 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1965 'transactions are not supported', __FUNCTION__);
1966 }
1967
1968 // }}}
1969 // {{{ function commit($savepoint = null)
1970
1982 function commit($savepoint = null)
1983 {
1984 $this->debug('Committing transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
1985 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
1986 'commiting transactions is not supported', __FUNCTION__);
1987 }
1988
1989 // }}}
1990 // {{{ function rollback($savepoint = null)
1991
2003 function rollback($savepoint = null)
2004 {
2005 $this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
2006 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2007 'rolling back transactions is not supported', __FUNCTION__);
2008 }
2009
2010 // }}}
2011 // {{{ function inTransaction($ignore_nested = false)
2012
2024 function inTransaction($ignore_nested = false)
2025 {
2026 if (!$ignore_nested && isset($this->nested_transaction_counter)) {
2028 }
2029 return $this->in_transaction;
2030 }
2031
2032 // }}}
2033 // {{{ function setTransactionIsolation($isolation)
2034
2051 function setTransactionIsolation($isolation, $options = array())
2052 {
2053 $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
2054 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2055 'isolation level setting is not supported', __FUNCTION__);
2056 }
2057
2058 // }}}
2059 // {{{ function beginNestedTransaction($savepoint = false)
2060
2075 {
2076 if ($this->in_transaction) {
2078 $savepoint = sprintf($this->options['savepoint_format'], $this->nested_transaction_counter);
2079 if ($this->supports('savepoints') && $savepoint) {
2080 return $this->beginTransaction($savepoint);
2081 }
2082 return MDB2_OK;
2083 }
2084 $this->has_transaction_error = false;
2085 $result = $this->beginTransaction();
2086 $this->nested_transaction_counter = 1;
2087 return $result;
2088 }
2089
2090 // }}}
2091 // {{{ function completeNestedTransaction($force_rollback = false, $release = false)
2092
2110 function completeNestedTransaction($force_rollback = false)
2111 {
2112 if ($this->nested_transaction_counter > 1) {
2113 $savepoint = sprintf($this->options['savepoint_format'], $this->nested_transaction_counter);
2114 if ($this->supports('savepoints') && $savepoint) {
2115 if ($force_rollback || $this->has_transaction_error) {
2116 $result = $this->rollback($savepoint);
2117 if (!PEAR::isError($result)) {
2118 $result = false;
2119 $this->has_transaction_error = false;
2120 }
2121 } else {
2122 $result = $this->commit($savepoint);
2123 }
2124 } else {
2125 $result = MDB2_OK;
2126 }
2128 return $result;
2129 }
2130
2131 $this->nested_transaction_counter = null;
2132 $result = MDB2_OK;
2133
2134 // transaction has not yet been rolled back
2135 if ($this->in_transaction) {
2136 if ($force_rollback || $this->has_transaction_error) {
2137 $result = $this->rollback();
2138 if (!PEAR::isError($result)) {
2139 $result = false;
2140 }
2141 } else {
2142 $result = $this->commit();
2143 }
2144 }
2145 $this->has_transaction_error = false;
2146 return $result;
2147 }
2148
2149 // }}}
2150 // {{{ function failNestedTransaction($error = null, $immediately = false)
2151
2167 function failNestedTransaction($error = null, $immediately = false)
2168 {
2169 if (is_null($error)) {
2170 $error = $this->has_transaction_error ? $this->has_transaction_error : true;
2171 } elseif (!$error) {
2172 $error = true;
2173 }
2174 $this->has_transaction_error = $error;
2175 if (!$immediately) {
2176 return MDB2_OK;
2177 }
2178 return $this->rollback();
2179 }
2180
2181 // }}}
2182 // {{{ function getNestedTransactionError()
2183
2198 {
2200 }
2201
2202 // }}}
2203 // {{{ connect()
2204
2210 function connect()
2211 {
2212 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2213 'method not implemented', __FUNCTION__);
2214 }
2215
2216 // }}}
2217 // {{{ setCharset($charset, $connection = null)
2218
2227 function setCharset($charset, $connection = null)
2228 {
2229 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2230 'method not implemented', __FUNCTION__);
2231 }
2232
2233 // }}}
2234 // {{{ function disconnect($force = true)
2235
2247 function disconnect($force = true)
2248 {
2249 $this->connection = 0;
2250 $this->connected_dsn = array();
2251 $this->connected_database_name = '';
2252 $this->opened_persistent = null;
2253 $this->connected_server_info = '';
2254 $this->in_transaction = null;
2255 $this->nested_transaction_counter = null;
2256 return MDB2_OK;
2257 }
2258
2259 // }}}
2260 // {{{ function setDatabase($name)
2261
2272 {
2273 $previous_database_name = (isset($this->database_name)) ? $this->database_name : '';
2274 $this->database_name = $name;
2275 $this->disconnect(false);
2276 return $previous_database_name;
2277 }
2278
2279 // }}}
2280 // {{{ function getDatabase()
2281
2289 function getDatabase()
2290 {
2291 return $this->database_name;
2292 }
2293
2294 // }}}
2295 // {{{ function setDSN($dsn)
2296
2306 function setDSN($dsn)
2307 {
2308 $dsn_default = $GLOBALS['_MDB2_dsninfo_default'];
2310 if (array_key_exists('database', $dsn)) {
2311 $this->database_name = $dsn['database'];
2312 unset($dsn['database']);
2313 }
2314 $this->dsn = array_merge($dsn_default, $dsn);
2315 return $this->disconnect(false);
2316 }
2317
2318 // }}}
2319 // {{{ function getDSN($type = 'string', $hidepw = false)
2320
2331 function getDSN($type = 'string', $hidepw = false)
2332 {
2333 $dsn = array_merge($GLOBALS['_MDB2_dsninfo_default'], $this->dsn);
2334 $dsn['phptype'] = $this->phptype;
2335 $dsn['database'] = $this->database_name;
2336 if ($hidepw) {
2337 $dsn['password'] = $hidepw;
2338 }
2339 switch ($type) {
2340 // expand to include all possible options
2341 case 'string':
2342 $dsn = $dsn['phptype'].
2343 ($dsn['dbsyntax'] ? ('('.$dsn['dbsyntax'].')') : '').
2344 '://'.$dsn['username'].':'.
2345 $dsn['password'].'@'.$dsn['hostspec'].
2346 ($dsn['port'] ? (':'.$dsn['port']) : '').
2347 '/'.$dsn['database'];
2348 break;
2349 case 'array':
2350 default:
2351 break;
2352 }
2353 return $dsn;
2354 }
2355
2356 // }}}
2357 // {{{ function &standaloneQuery($query, $types = null, $is_manip = false)
2358
2371 function &standaloneQuery($query, $types = null, $is_manip = false)
2372 {
2375 $this->offset = $this->limit = 0;
2376 $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
2377
2378 $connection = $this->getConnection();
2379 if (PEAR::isError($connection)) {
2380 return $connection;
2381 }
2382
2383 $result =& $this->_doQuery($query, $is_manip, $connection, false);
2384 if (PEAR::isError($result)) {
2385 return $result;
2386 }
2387
2388 if ($is_manip) {
2389 $affected_rows = $this->_affectedRows($connection, $result);
2390 return $affected_rows;
2391 }
2392 $result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
2393 return $result;
2394 }
2395
2396 // }}}
2397 // {{{ function _modifyQuery($query, $is_manip, $limit, $offset)
2398
2411 function _modifyQuery($query, $is_manip, $limit, $offset)
2412 {
2413 return $query;
2414 }
2415
2416 // }}}
2417 // {{{ function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
2418
2430 function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
2431 {
2432 $this->last_query = $query;
2433 $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
2434 if ($result) {
2435 if (PEAR::isError($result)) {
2436 return $result;
2437 }
2438 $query = $result;
2439 }
2440 $err =& $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2441 'method not implemented', __FUNCTION__);
2442 return $err;
2443 }
2444
2445 // }}}
2446 // {{{ function _affectedRows($connection, $result = null)
2447
2459 {
2460 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2461 'method not implemented', __FUNCTION__);
2462 }
2463
2464 // }}}
2465 // {{{ function &exec($query)
2466
2476 function &exec($query)
2477 {
2480 $this->offset = $this->limit = 0;
2481 $query = $this->_modifyQuery($query, true, $limit, $offset);
2482
2483 $connection = $this->getConnection();
2484 if (PEAR::isError($connection)) {
2485 return $connection;
2486 }
2487
2488 $result =& $this->_doQuery($query, true, $connection, $this->database_name);
2489 if (PEAR::isError($result)) {
2490 return $result;
2491 }
2492
2493 $affectedRows = $this->_affectedRows($connection, $result);
2494 return $affectedRows;
2495 }
2496
2497 // }}}
2498 // {{{ function &query($query, $types = null, $result_class = true, $result_wrap_class = false)
2499
2513 function &query($query, $types = null, $result_class = true, $result_wrap_class = false)
2514 {
2517 $this->offset = $this->limit = 0;
2518 $query = $this->_modifyQuery($query, false, $limit, $offset);
2519
2520 $connection = $this->getConnection();
2521 if (PEAR::isError($connection)) {
2522 return $connection;
2523 }
2524
2525 $result =& $this->_doQuery($query, false, $connection, $this->database_name);
2526 if (PEAR::isError($result)) {
2527 return $result;
2528 }
2529
2530 $result =& $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset);
2531 return $result;
2532 }
2533
2534 // }}}
2535 // {{{ function &_wrapResult($result, $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null)
2536
2552 function &_wrapResult($result, $types = array(), $result_class = true,
2553 $result_wrap_class = false, $limit = null, $offset = null)
2554 {
2555 if ($types === true) {
2556 if ($this->supports('result_introspection')) {
2557 $this->loadModule('Reverse', null, true);
2558 $tableInfo = $this->reverse->tableInfo($result);
2559 if (PEAR::isError($tableInfo)) {
2560 return $tableInfo;
2561 }
2562 $types = array();
2563 foreach ($tableInfo as $field) {
2564 $types[] = $field['mdb2type'];
2565 }
2566 } else {
2567 $types = null;
2568 }
2569 }
2570
2571 if ($result_class === true) {
2572 $result_class = $this->options['result_buffering']
2573 ? $this->options['buffered_result_class'] : $this->options['result_class'];
2574 }
2575
2576 if ($result_class) {
2577 $class_name = sprintf($result_class, $this->phptype);
2578 if (!MDB2::classExists($class_name)) {
2579 $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
2580 'result class does not exist '.$class_name, __FUNCTION__);
2581 return $err;
2582 }
2583 $result = new $class_name($this, $result, $limit, $offset);
2585 $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
2586 'result class is not extended from MDB2_Result_Common', __FUNCTION__);
2587 return $err;
2588 }
2589 if (!empty($types)) {
2590 $err = $result->setResultTypes($types);
2591 if (PEAR::isError($err)) {
2592 $result->free();
2593 return $err;
2594 }
2595 }
2596 }
2597 if ($result_wrap_class === true) {
2598 $result_wrap_class = $this->options['result_wrap_class'];
2599 }
2600 if ($result_wrap_class) {
2601 if (!MDB2::classExists($result_wrap_class)) {
2602 $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
2603 'result wrap class does not exist '.$result_wrap_class, __FUNCTION__);
2604 return $err;
2605 }
2606 $result = new $result_wrap_class($result, $this->fetchmode);
2607 }
2608 return $result;
2609 }
2610
2611 // }}}
2612 // {{{ function getServerVersion($native = false)
2613
2623 function getServerVersion($native = false)
2624 {
2625 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2626 'method not implemented', __FUNCTION__);
2627 }
2628
2629 // }}}
2630 // {{{ function setLimit($limit, $offset = null)
2631
2642 function setLimit($limit, $offset = null)
2643 {
2644 if (!$this->supports('limit_queries')) {
2645 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2646 'limit is not supported by this driver', __FUNCTION__);
2647 }
2648 $limit = (int)$limit;
2649 if ($limit < 0) {
2650 return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2651 'it was not specified a valid selected range row limit', __FUNCTION__);
2652 }
2653 $this->limit = $limit;
2654 if (!is_null($offset)) {
2655 $offset = (int)$offset;
2656 if ($offset < 0) {
2657 return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2658 'it was not specified a valid first selected range row', __FUNCTION__);
2659 }
2660 $this->offset = $offset;
2661 }
2662 return MDB2_OK;
2663 }
2664
2665 // }}}
2666 // {{{ function subSelect($query, $type = false)
2667
2680 function subSelect($query, $type = false)
2681 {
2682 if ($this->supports('sub_selects') === true) {
2683 return $query;
2684 }
2685
2686 if (!$this->supports('sub_selects')) {
2687 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2688 'method not implemented', __FUNCTION__);
2689 }
2690
2691 $col = $this->queryCol($query, $type);
2692 if (PEAR::isError($col)) {
2693 return $col;
2694 }
2695 if (!is_array($col) || count($col) == 0) {
2696 return 'NULL';
2697 }
2698 if ($type) {
2699 $this->loadModule('Datatype', null, true);
2700 return $this->datatype->implodeArray($col, $type);
2701 }
2702 return implode(', ', $col);
2703 }
2704
2705 // }}}
2706 // {{{ function replace($table, $fields)
2707
2771 function replace($table, $fields)
2772 {
2773 if (!$this->supports('replace')) {
2774 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
2775 'replace query is not supported', __FUNCTION__);
2776 }
2777 $count = count($fields);
2778 $condition = $values = array();
2779 for ($colnum = 0, reset($fields); $colnum < $count; next($fields), $colnum++) {
2780 $name = key($fields);
2781 if (isset($fields[$name]['null']) && $fields[$name]['null']) {
2782 $value = 'NULL';
2783 } else {
2784 $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
2785 $value = $this->quote($fields[$name]['value'], $type);
2786 }
2787 $values[$name] = $value;
2788 if (isset($fields[$name]['key']) && $fields[$name]['key']) {
2789 if ($value === 'NULL') {
2790 return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
2791 'key value '.$name.' may not be NULL', __FUNCTION__);
2792 }
2793 $condition[] = $name . '=' . $value;
2794 }
2795 }
2796 if (empty($condition)) {
2797 return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
2798 'not specified which fields are keys', __FUNCTION__);
2799 }
2800
2801 $result = null;
2804 return $result;
2805 }
2806
2807 $connection = $this->getConnection();
2808 if (PEAR::isError($connection)) {
2809 return $connection;
2810 }
2811
2812 $condition = ' WHERE '.implode(' AND ', $condition);
2813 $query = "DELETE FROM $table$condition";
2814 $result =& $this->_doQuery($query, true, $connection);
2815 if (!PEAR::isError($result)) {
2816 $affected_rows = $this->_affectedRows($connection, $result);
2817 $insert = implode(', ', array_keys($values));
2818 $values = implode(', ', $values);
2819 $query = "INSERT INTO $table ($insert) VALUES ($values)";
2820 $result =& $this->_doQuery($query, true, $connection);
2821 if (!PEAR::isError($result)) {
2822 $affected_rows += $this->_affectedRows($connection, $result);;
2823 }
2824 }
2825
2826 if (!$in_transaction) {
2827 if (PEAR::isError($result)) {
2828 $this->rollback();
2829 } else {
2830 $result = $this->commit();
2831 }
2832 }
2833
2834 if (PEAR::isError($result)) {
2835 return $result;
2836 }
2837
2838 return $affected_rows;
2839 }
2840
2841 // }}}
2842 // {{{ function &prepare($query, $types = null, $result_types = null, $lobs = array())
2843
2866 function &prepare($query, $types = null, $result_types = null, $lobs = array())
2867 {
2868 $is_manip = ($result_types === MDB2_PREPARE_MANIP);
2871 $this->offset = $this->limit = 0;
2872 $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
2873 if ($result) {
2874 if (PEAR::isError($result)) {
2875 return $result;
2876 }
2877 $query = $result;
2878 }
2879 $placeholder_type_guess = $placeholder_type = null;
2880 $question = '?';
2881 $colon = ':';
2882 $positions = array();
2883 $position = 0;
2884 $ignores = $this->sql_comments;
2885 $ignores[] = $this->string_quoting;
2886 $ignores[] = $this->identifier_quoting;
2887 while ($position < strlen($query)) {
2888 $q_position = strpos($query, $question, $position);
2889 $c_position = strpos($query, $colon, $position);
2890 if ($q_position && $c_position) {
2891 $p_position = min($q_position, $c_position);
2892 } elseif ($q_position) {
2893 $p_position = $q_position;
2894 } elseif ($c_position) {
2895 $p_position = $c_position;
2896 } else {
2897 break;
2898 }
2899 if (is_null($placeholder_type)) {
2900 $placeholder_type_guess = $query[$p_position];
2901 }
2902
2903 $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
2904 if (PEAR::isError($new_pos)) {
2905 return $new_pos;
2906 }
2907 if ($new_pos != $position) {
2908 $position = $new_pos;
2909 continue; //evaluate again starting from the new position
2910 }
2911
2912 if ($query[$position] == $placeholder_type_guess) {
2913 if (is_null($placeholder_type)) {
2914 $placeholder_type = $query[$p_position];
2915 $question = $colon = $placeholder_type;
2916 if (!empty($types) && is_array($types)) {
2917 if ($placeholder_type == ':') {
2918 if (is_int(key($types))) {
2919 $types_tmp = $types;
2920 $types = array();
2921 $count = -1;
2922 }
2923 } else {
2924 $types = array_values($types);
2925 }
2926 }
2927 }
2928 if ($placeholder_type == ':') {
2929 $parameter = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
2930 if ($parameter === '') {
2931 $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2932 'named parameter with an empty name', __FUNCTION__);
2933 return $err;
2934 }
2935 $positions[$p_position] = $parameter;
2936 $query = substr_replace($query, '?', $position, strlen($parameter)+1);
2937 // use parameter name in type array
2938 if (isset($count) && isset($types_tmp[++$count])) {
2939 $types[$parameter] = $types_tmp[$count];
2940 }
2941 } else {
2942 $positions[$p_position] = count($positions);
2943 }
2944 $position = $p_position + 1;
2945 } else {
2946 $position = $p_position;
2947 }
2948 }
2949 $class_name = 'MDB2_Statement_'.$this->phptype;
2950 $statement = null;
2951 $obj = new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
2952 $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
2953 return $obj;
2954 }
2955
2956 // }}}
2957 // {{{ function _skipDelimitedStrings($query, $position, $p_position)
2958
2974 function _skipDelimitedStrings($query, $position, $p_position)
2975 {
2976 $ignores = $this->sql_comments;
2977 $ignores[] = $this->string_quoting;
2978 $ignores[] = $this->identifier_quoting;
2979
2980 foreach ($ignores as $ignore) {
2981 if (!empty($ignore['start'])) {
2982 if (is_int($start_quote = strpos($query, $ignore['start'], $position)) && $start_quote < $p_position) {
2983 $end_quote = $start_quote;
2984 do {
2985 if (!is_int($end_quote = strpos($query, $ignore['end'], $end_quote + 1))) {
2986 if ($ignore['end'] === "\n") {
2987 $end_quote = strlen($query) - 1;
2988 } else {
2989 $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
2990 'query with an unterminated text string specified', __FUNCTION__);
2991 return $err;
2992 }
2993 }
2994 } while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']);
2995 $position = $end_quote + 1;
2996 return $position;
2997 }
2998 }
2999 }
3000 return $position;
3001 }
3002
3003 // }}}
3004 // {{{ function quote($value, $type = null, $quote = true)
3005
3020 function quote($value, $type = null, $quote = true, $escape_wildcards = false)
3021 {
3022 $result = $this->loadModule('Datatype', null, true);
3023 if (PEAR::isError($result)) {
3024 return $result;
3025 }
3026
3027 return $this->datatype->quote($value, $type, $quote, $escape_wildcards);
3028 }
3029
3030 // }}}
3031 // {{{ function getDeclaration($type, $name, $field)
3032
3046 function getDeclaration($type, $name, $field)
3047 {
3048 $result = $this->loadModule('Datatype', null, true);
3049 if (PEAR::isError($result)) {
3050 return $result;
3051 }
3052 return $this->datatype->getDeclaration($type, $name, $field);
3053 }
3054
3055 // }}}
3056 // {{{ function compareDefinition($current, $previous)
3057
3068 function compareDefinition($current, $previous)
3069 {
3070 $result = $this->loadModule('Datatype', null, true);
3071 if (PEAR::isError($result)) {
3072 return $result;
3073 }
3074 return $this->datatype->compareDefinition($current, $previous);
3075 }
3076
3077 // }}}
3078 // {{{ function supports($feature)
3079
3092 function supports($feature)
3093 {
3094 if (array_key_exists($feature, $this->supported)) {
3095 return $this->supported[$feature];
3096 }
3097 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3098 "unknown support feature $feature", __FUNCTION__);
3099 }
3100
3101 // }}}
3102 // {{{ function getSequenceName($sqn)
3103
3113 function getSequenceName($sqn)
3114 {
3115 return sprintf($this->options['seqname_format'],
3116 preg_replace('/[^a-z0-9_\$.]/i', '_', $sqn));
3117 }
3118
3119 // }}}
3120 // {{{ function getIndexName($idx)
3121
3131 function getIndexName($idx)
3132 {
3133 return sprintf($this->options['idxname_format'],
3134 preg_replace('/[^a-z0-9_\$]/i', '_', $idx));
3135 }
3136
3137 // }}}
3138 // {{{ function nextID($seq_name, $ondemand = true)
3139
3150 function nextID($seq_name, $ondemand = true)
3151 {
3152 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3153 'method not implemented', __FUNCTION__);
3154 }
3155
3156 // }}}
3157 // {{{ function lastInsertID($table = null, $field = null)
3158
3170 function lastInsertID($table = null, $field = null)
3171 {
3172 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3173 'method not implemented', __FUNCTION__);
3174 }
3175
3176 // }}}
3177 // {{{ function currID($seq_name)
3178
3188 function currID($seq_name)
3189 {
3190 $this->warnings[] = 'database does not support getting current
3191 sequence value, the sequence value was incremented';
3192 return $this->nextID($seq_name);
3193 }
3194
3195 // }}}
3196 // {{{ function queryOne($query, $type = null, $colnum = 0)
3197
3214 function queryOne($query, $type = null, $colnum = 0)
3215 {
3216 $result = $this->query($query, $type);
3218 return $result;
3219 }
3220
3221 $one = $result->fetchOne($colnum);
3222 $result->free();
3223 return $one;
3224 }
3225
3226 // }}}
3227 // {{{ function queryRow($query, $types = null, $fetchmode = MDB2_FETCHMODE_DEFAULT)
3228
3246 {
3247 $result = $this->query($query, $types);
3249 return $result;
3250 }
3251
3252 $row = $result->fetchRow($fetchmode);
3253 $result->free();
3254 return $row;
3255 }
3256
3257 // }}}
3258 // {{{ function queryCol($query, $type = null, $colnum = 0)
3259
3275 function queryCol($query, $type = null, $colnum = 0)
3276 {
3277 $result = $this->query($query, $type);
3279 return $result;
3280 }
3281
3282 $col = $result->fetchCol($colnum);
3283 $result->free();
3284 return $col;
3285 }
3286
3287 // }}}
3288 // {{{ function queryAll($query, $types = null, $fetchmode = MDB2_FETCHMODE_DEFAULT, $rekey = false, $force_array = false, $group = false)
3289
3315 $rekey = false, $force_array = false, $group = false)
3316 {
3317 $result = $this->query($query, $types);
3319 return $result;
3320 }
3321
3322 $all = $result->fetchAll($fetchmode, $rekey, $force_array, $group);
3323 $result->free();
3324 return $all;
3325 }
3326
3327 // }}}
3328}
3329
3330// }}}
3331// {{{ class MDB2_Result
3332
3341{
3342}
3343
3344// }}}
3345// {{{ class MDB2_Result_Common extends MDB2_Result
3346require_once('./Services/Database/interfaces/interface.ilDBStatement.php');
3355{
3356 // {{{ Variables (Properties)
3357
3358 var $db;
3360 var $rownum = -1;
3361 var $types = array();
3362 var $values = array();
3367
3368 // }}}
3369 // {{{ constructor: function __construct($db, $result, $limit = 0, $offset = 0)
3370
3374 function __construct($db, $result, $limit = 0, $offset = 0)
3375 {
3376 $this->db = $db;
3377 $this->result = $result;
3378 $this->offset = $offset;
3379 $this->limit = max(0, $limit - 1);
3380 }
3381
3382
3383 public function fetch($fetch_mode = ilDBConstants::FETCHMODE_ASSOC) {
3384 return $this->fetchRow($fetch_mode);
3385 }
3386
3387
3388 public function fetchObject() {
3390 }
3391
3392
3393 public function fetchAssoc() {
3395 }
3396
3397 // }}}
3398 // {{{ function MDB2_Result_Common($db, $result, $limit = 0, $offset = 0)
3399
3403 function MDB2_Result_Common($db, $result, $limit = 0, $offset = 0)
3404 {
3405 $this->__construct($db, $result, $limit, $offset);
3406 }
3407
3408 // }}}
3409 // {{{ function setResultTypes($types)
3410
3433 {
3434 $load = $this->db->loadModule('Datatype', null, true);
3435 if (PEAR::isError($load)) {
3436 return $load;
3437 }
3438 $types = $this->db->datatype->checkResultTypes($types);
3439 if (PEAR::isError($types)) {
3440 return $types;
3441 }
3442 $this->types = $types;
3443 return MDB2_OK;
3444 }
3445
3446 // }}}
3447 // {{{ function seek($rownum = 0)
3448
3458 function seek($rownum = 0)
3459 {
3460 $target_rownum = $rownum - 1;
3461 if ($this->rownum > $target_rownum) {
3462 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3463 'seeking to previous rows not implemented', __FUNCTION__);
3464 }
3465 while ($this->rownum < $target_rownum) {
3466 $this->fetchRow();
3467 }
3468 return MDB2_OK;
3469 }
3470
3471 // }}}
3472 // {{{ function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
3473
3484 function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
3485 {
3486 $err =& $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3487 'method not implemented', __FUNCTION__);
3488 return $err;
3489 }
3490
3491 // }}}
3492 // {{{ function fetchOne($colnum = 0)
3493
3504 function fetchOne($colnum = 0, $rownum = null)
3505 {
3506 $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
3507 $row = $this->fetchRow($fetchmode, $rownum);
3508 if (!is_array($row) || PEAR::isError($row)) {
3509 return $row;
3510 }
3511 if (!array_key_exists($colnum, $row)) {
3512 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3513 'column is not defined in the result set: '.$colnum, __FUNCTION__);
3514 }
3515 return $row[$colnum];
3516 }
3517
3518 // }}}
3519 // {{{ function fetchCol($colnum = 0)
3520
3530 function fetchCol($colnum = 0)
3531 {
3532 $column = array();
3533 $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
3534 $row = $this->fetchRow($fetchmode);
3535 if (is_array($row)) {
3536 if (!array_key_exists($colnum, $row)) {
3537 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3538 'column is not defined in the result set: '.$colnum, __FUNCTION__);
3539 }
3540 do {
3541 $column[] = $row[$colnum];
3542 } while (is_array($row = $this->fetchRow($fetchmode)));
3543 }
3544 if (PEAR::isError($row)) {
3545 return $row;
3546 }
3547 return $column;
3548 }
3549
3550 // }}}
3551 // {{{ function fetchAll($fetchmode = MDB2_FETCHMODE_DEFAULT, $rekey = false, $force_array = false, $group = false)
3552
3576 function fetchAll($fetchmode = MDB2_FETCHMODE_DEFAULT, $rekey = false,
3577 $force_array = false, $group = false)
3578 {
3579 $all = array();
3580 $row = $this->fetchRow($fetchmode);
3581 if (PEAR::isError($row)) {
3582 return $row;
3583 } elseif (!$row) {
3584 return $all;
3585 }
3586
3587 $shift_array = $rekey ? false : null;
3588 if (!is_null($shift_array)) {
3589 if (is_object($row)) {
3590 $colnum = count(get_object_vars($row));
3591 } else {
3592 $colnum = count($row);
3593 }
3594 if ($colnum < 2) {
3595 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3596 'rekey feature requires atleast 2 column', __FUNCTION__);
3597 }
3598 $shift_array = (!$force_array && $colnum == 2);
3599 }
3600
3601 if ($rekey) {
3602 do {
3603 if (is_object($row)) {
3604 $arr = get_object_vars($row);
3605 $key = reset($arr);
3606 unset($row->{$key});
3607 } else {
3608 if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
3609 $key = reset($row);
3610 unset($row[key($row)]);
3611 } else {
3612 $key = array_shift($row);
3613 }
3614 if ($shift_array) {
3615 $row = array_shift($row);
3616 }
3617 }
3618 if ($group) {
3619 $all[$key][] = $row;
3620 } else {
3621 $all[$key] = $row;
3622 }
3623 } while (($row = $this->fetchRow($fetchmode)));
3624 } elseif ($fetchmode & MDB2_FETCHMODE_FLIPPED) {
3625 do {
3626 foreach ($row as $key => $val) {
3627 $all[$key][] = $val;
3628 }
3629 } while (($row = $this->fetchRow($fetchmode)));
3630 } else {
3631 do {
3632 $all[] = $row;
3633 } while (($row = $this->fetchRow($fetchmode)));
3634 }
3635
3636 return $all;
3637 }
3638
3639 // }}}
3640 // {{{ function rowCount()
3647 function rowCount()
3648 {
3649 return $this->rownum + 1;
3650 }
3651
3652 // }}}
3653 // {{{ function numRows()
3654
3662 function numRows()
3663 {
3664 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3665 'method not implemented', __FUNCTION__);
3666 }
3667
3668 // }}}
3669 // {{{ function nextResult()
3670
3678 function nextResult()
3679 {
3680 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3681 'method not implemented', __FUNCTION__);
3682 }
3683
3684 // }}}
3685 // {{{ function getColumnNames()
3686
3700 function getColumnNames($flip = false)
3701 {
3702 if (!isset($this->column_names)) {
3703 $result = $this->_getColumnNames();
3704 if (PEAR::isError($result)) {
3705 return $result;
3706 }
3707 $this->column_names = $result;
3708 }
3709 if ($flip) {
3710 return array_flip($this->column_names);
3711 }
3712 return $this->column_names;
3713 }
3714
3715 // }}}
3716 // {{{ function _getColumnNames()
3717
3729 {
3730 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3731 'method not implemented', __FUNCTION__);
3732 }
3733
3734 // }}}
3735 // {{{ function numCols()
3736
3745 function numCols()
3746 {
3747 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3748 'method not implemented', __FUNCTION__);
3749 }
3750
3751 // }}}
3752 // {{{ function getResource()
3753
3761 function getResource()
3762 {
3763 return $this->result;
3764 }
3765
3766 // }}}
3767 // {{{ function bindColumn($column, &$value, $type = null)
3768
3780 function bindColumn($column, &$value, $type = null)
3781 {
3782 if (!is_numeric($column)) {
3783 $column_names = $this->getColumnNames();
3784 if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
3785 if ($this->db->options['field_case'] == CASE_LOWER) {
3786 $column = strtolower($column);
3787 } else {
3788 $column = strtoupper($column);
3789 }
3790 }
3791 $column = $column_names[$column];
3792 }
3793 $this->values[$column] =& $value;
3794 if (!is_null($type)) {
3795 $this->types[$column] = $type;
3796 }
3797 return MDB2_OK;
3798 }
3799
3800 // }}}
3801 // {{{ function _assignBindColumns($row)
3802
3813 {
3814 $row = array_values($row);
3815 foreach ($row as $column => $value) {
3816 if (array_key_exists($column, $this->values)) {
3817 $this->values[$column] = $value;
3818 }
3819 }
3820 return MDB2_OK;
3821 }
3822
3823 // }}}
3824 // {{{ function free()
3825
3833 function free()
3834 {
3835 $this->result = false;
3836 return MDB2_OK;
3837 }
3838
3839 // }}}
3845 public function execute($a_data = null) {
3846 $res = $this->result->execute($a_data);
3847 if (MDB2::isError($res)) {
3848 throw new ilDatabaseException("There was an MDB2 error executing the prepared query: ".$this->result->getMessage());
3849 }
3850 return $res;
3851 }
3852}
3853
3854// }}}
3855// {{{ class MDB2_Row
3856
3865{
3866 // {{{ constructor: function __construct(&$row)
3867
3874 {
3875 foreach ($row as $key => $value) {
3876 $this->$key = &$row[$key];
3877 }
3878 }
3879
3880 // }}}
3881 // {{{ function MDB2_Row(&$row)
3882
3888 function MDB2_Row(&$row)
3889 {
3890 $this->__construct($row);
3891 }
3892
3893 // }}}
3894}
3895
3896// }}}
3897// {{{ class MDB2_Statement_Common
3898
3907{
3908 // {{{ Variables (Properties)
3909
3910 var $db;
3915 var $values = array();
3919
3920 // }}}
3921 // {{{ constructor: function __construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
3922
3926 function __construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
3927 {
3928 $this->db =& $db;
3929 $this->statement =& $statement;
3930 $this->positions = $positions;
3931 $this->query = $query;
3932 $this->types = (array)$types;
3933 $this->result_types = (array)$result_types;
3934 $this->limit = $limit;
3935 $this->is_manip = $is_manip;
3936 $this->offset = $offset;
3937 }
3938
3939 // }}}
3940 // {{{ function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
3941
3945 function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
3946 {
3948 }
3949
3950 // }}}
3951 // {{{ function bindValue($parameter, &$value, $type = null)
3952
3966 function bindValue($parameter, $value, $type = null)
3967 {
3968 if (!is_numeric($parameter)) {
3969 $parameter = preg_replace('/^:(.*)$/', '\\1', $parameter);
3970 }
3971 if (!in_array($parameter, $this->positions)) {
3972 return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
3973 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
3974 }
3975 $this->values[$parameter] = $value;
3976 if (!is_null($type)) {
3977 $this->types[$parameter] = $type;
3978 }
3979 return MDB2_OK;
3980 }
3981
3982 // }}}
3983 // {{{ function bindValueArray($values, $types = null)
3984
3999 {
4000 $types = is_array($types) ? array_values($types) : array_fill(0, count($values), null);
4001 $parameters = array_keys($values);
4002 foreach ($parameters as $key => $parameter) {
4003 $err = $this->bindValue($parameter, $values[$parameter], $types[$key]);
4004 if (PEAR::isError($err)) {
4005 return $err;
4006 }
4007 }
4008 return MDB2_OK;
4009 }
4010
4011 // }}}
4012 // {{{ function bindParam($parameter, &$value, $type = null)
4013
4027 function bindParam($parameter, &$value, $type = null)
4028 {
4029 if (!is_numeric($parameter)) {
4030 $parameter = preg_replace('/^:(.*)$/', '\\1', $parameter);
4031 }
4032 if (!in_array($parameter, $this->positions)) {
4033 return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
4034 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
4035 }
4036 $this->values[$parameter] =& $value;
4037 if (!is_null($type)) {
4038 $this->types[$parameter] = $type;
4039 }
4040 return MDB2_OK;
4041 }
4042
4043 // }}}
4044 // {{{ function bindParamArray(&$values, $types = null)
4045
4059 function bindParamArray(&$values, $types = null)
4060 {
4061 $types = is_array($types) ? array_values($types) : array_fill(0, count($values), null);
4062 $parameters = array_keys($values);
4063 foreach ($parameters as $key => $parameter) {
4064 $err = $this->bindParam($parameter, $values[$parameter], $types[$key]);
4065 if (PEAR::isError($err)) {
4066 return $err;
4067 }
4068 }
4069 return MDB2_OK;
4070 }
4071
4072 // }}}
4073 // {{{ function &execute($values = null, $result_class = true, $result_wrap_class = false)
4074
4088 function &execute($values = null, $result_class = true, $result_wrap_class = false)
4089 {
4090 if (is_null($this->positions)) {
4091 return $this->db->raiseError(MDB2_ERROR, null, null,
4092 'Prepared statement has already been freed', __FUNCTION__);
4093 }
4094
4095 $values = (array)$values;
4096 if (!empty($values)) {
4097 $err = $this->bindValueArray($values);
4098 if (PEAR::isError($err)) {
4099 return $this->db->raiseError(MDB2_ERROR, null, null,
4100 'Binding Values failed with message: ' . $err->getMessage(), __FUNCTION__);
4101 }
4102 }
4103 $result =& $this->_execute($result_class, $result_wrap_class);
4104 return $result;
4105 }
4106
4107 // }}}
4108 // {{{ function &_execute($result_class = true, $result_wrap_class = false)
4109
4120 function &_execute($result_class = true, $result_wrap_class = false)
4121 {
4122 $this->last_query = $this->query;
4123 $query = '';
4124 $last_position = 0;
4125 foreach ($this->positions as $current_position => $parameter) {
4126 if (!array_key_exists($parameter, $this->values)) {
4127 return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
4128 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
4129 }
4130 $value = $this->values[$parameter];
4131 $query.= substr($this->query, $last_position, $current_position - $last_position);
4132 if (!isset($value)) {
4133 $value_quoted = 'NULL';
4134 } else {
4135 $type = !empty($this->types[$parameter]) ? $this->types[$parameter] : null;
4136 $value_quoted = $this->db->quote($value, $type);
4137 if (PEAR::isError($value_quoted)) {
4138 return $value_quoted;
4139 }
4140 }
4141 $query.= $value_quoted;
4142 $last_position = $current_position + 1;
4143 }
4144 $query.= substr($this->query, $last_position);
4145
4146 $this->db->offset = $this->offset;
4147 $this->db->limit = $this->limit;
4148 if ($this->is_manip) {
4149 $result = $this->db->exec($query);
4150 } else {
4151 $result =& $this->db->query($query, $this->result_types, $result_class, $result_wrap_class);
4152 }
4153 return $result;
4154 }
4155
4156 // }}}
4157 // {{{ function free()
4158
4166 function free()
4167 {
4168 if (is_null($this->positions)) {
4169 return $this->db->raiseError(MDB2_ERROR, null, null,
4170 'Prepared statement has already been freed', __FUNCTION__);
4171 }
4172
4173 $this->statement = null;
4174 $this->positions = null;
4175 $this->query = null;
4176 $this->types = null;
4177 $this->result_types = null;
4178 $this->limit = null;
4179 $this->is_manip = null;
4180 $this->offset = null;
4181 $this->values = null;
4182
4183 return MDB2_OK;
4184 }
4185
4186 // }}}
4187}
4188
4189// }}}
4190// {{{ class MDB2_Module_Common
4191
4200{
4201 // {{{ Variables (Properties)
4202
4211
4212 // }}}
4213 // {{{ constructor: function __construct($db_index)
4214
4219 {
4220 $this->db_index = $db_index;
4221 }
4222
4223 // }}}
4224 // {{{ function MDB2_Module_Common($db_index)
4225
4230 {
4231 $this->__construct($db_index);
4232 }
4233
4234 // }}}
4235 // {{{ function &getDBInstance()
4236
4244 function &getDBInstance()
4245 {
4246 if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
4247 $result =& $GLOBALS['_MDB2_databases'][$this->db_index];
4248 } else {
4250 'could not find MDB2 instance');
4251 }
4252 return $result;
4253 }
4254
4255 // }}}
4256}
4257
4258// }}}
4259// {{{ function MDB2_closeOpenTransactions()
4260
4270{
4271 reset($GLOBALS['_MDB2_databases']);
4272 while (next($GLOBALS['_MDB2_databases'])) {
4273 $key = key($GLOBALS['_MDB2_databases']);
4274 if ($GLOBALS['_MDB2_databases'][$key]->opened_persistent
4275 && $GLOBALS['_MDB2_databases'][$key]->in_transaction
4276 ) {
4277 $GLOBALS['_MDB2_databases'][$key]->rollback();
4278 }
4279 }
4280}
4281
4282// }}}
4283// {{{ function MDB2_defaultDebugOutput(&$db, $scope, $message, $is_manip = null)
4284
4301function MDB2_defaultDebugOutput(&$db, $scope, $message, $context = array())
4302{
4303 $db->debug_output.= $scope.'('.$db->db_index.'): ';
4304 $db->debug_output.= $message.$db->getOption('log_line_break');
4305 return $message;
4306}
4307
4308// }}}
4309?>
sprintf('%.4f', $callTime)
$column
Definition: 39dropdown.php:62
$result
MDB2_defaultDebugOutput(&$db, $scope, $message, $context=array())
default debug output handler
Definition: MDB2.php:4301
const MDB2_ERROR_ACCESS_VIOLATION
Definition: MDB2.php:99
const MDB2_FETCHMODE_FLIPPED
For multi-dimensional results: normally the first level of arrays is the row number,...
Definition: MDB2.php:147
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78
const MDB2_PORTABILITY_ALL
Portability: turn on all portability features.
Definition: MDB2.php:215
const MDB2_ERROR_NODBSELECTED
Definition: MDB2.php:86
const MDB2_PORTABILITY_RTRIM
Portability: right trim the data output by query*() and fetch*().
Definition: MDB2.php:169
const MDB2_ERROR_DEADLOCK
Definition: MDB2.php:102
const MDB2_ERROR_INVALID_DATE
Definition: MDB2.php:84
const MDB2_FETCHMODE_DEFAULT
This is a special constant that tells MDB2 the user hasn't specified any particular get mode,...
Definition: MDB2.php:124
const MDB2_ERROR_CANNOT_DELETE
Definition: MDB2.php:88
const MDB2_ERROR_INVALID
Definition: MDB2.php:80
const MDB2_ERROR_CONSTRAINT_NOT_NULL
Definition: MDB2.php:101
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
const MDB2_ERROR_MISMATCH
Definition: MDB2.php:79
const MDB2_ERROR_SYNTAX
Definition: MDB2.php:74
const MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES
Portability: removes database/table qualifiers from associative indexes.
Definition: MDB2.php:209
const MDB2_ERROR_NOT_LOCKED
Definition: MDB2.php:93
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:76
const MDB2_ERROR_VALUE_COUNT_ON_ROW
Definition: MDB2.php:94
const MDB2_ERROR_CANNOT_CREATE
Definition: MDB2.php:87
const MDB2_ERROR_INVALID_NUMBER
Definition: MDB2.php:83
const MDB2_ERROR_EXTENSION_NOT_FOUND
Definition: MDB2.php:97
const MDB2_ERROR_LOADMODULE
Definition: MDB2.php:106
const MDB2_ERROR_INVALID_DSN
Definition: MDB2.php:95
$GLOBALS['_MDB2_databases']
These are global variables that are used to track the various class instances.
Definition: MDB2.php:224
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
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare()
Definition: MDB2.php:114
const MDB2_ERROR_NOT_CAPABLE
Definition: MDB2.php:81
const MDB2_ERROR_ALREADY_EXISTS
Definition: MDB2.php:77
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_DIVZERO
Definition: MDB2.php:85
const MDB2_ERROR_CONSTRAINT
Definition: MDB2.php:75
const MDB2_FETCHMODE_OBJECT
Column data as object properties.
Definition: MDB2.php:139
const MDB2_FETCHMODE_ORDERED
Column data indexed by numbers, ordered from 0 and up.
Definition: MDB2.php:129
const MDB2_ERROR_NOSUCHFIELD
Definition: MDB2.php:91
const MDB2_ERROR_CANNOT_ALTER
Definition: MDB2.php:103
const MDB2_ERROR_TRUNCATED
Definition: MDB2.php:82
const MDB2_ERROR_NEED_MORE_DATA
Definition: MDB2.php:92
const MDB2_ERROR
Definition: MDB2.php:73
const MDB2_ERROR_NOSUCHTABLE
Definition: MDB2.php:90
const MDB2_ERROR_CONNECT_FAILED
Definition: MDB2.php:96
const MDB2_ERROR_NOSUCHDB
Definition: MDB2.php:98
const MDB2_ERROR_CANNOT_REPLACE
Definition: MDB2.php:100
MDB2_closeOpenTransactions()
Close any open transactions form persistent connections.
Definition: MDB2.php:4269
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
Definition: MDB2.php:134
const MDB2_ERROR_CANNOT_DROP
Definition: MDB2.php:89
const PEAR_ERROR_RETURN
#+ ERROR constants
Definition: PEAR.php:31
$test
Definition: Utf8Test.php:84
while(false !==( $line=fgets( $in))) if(! $columns) $ignore
Definition: Utf8Test.php:63
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
An exception for terminatinating execution or to throw for unit testing.
disconnect($force=true)
Log out and disconnect from the database.
Definition: MDB2.php:2247
setTransactionIsolation($isolation, $options=array())
Set the transacton isolation level.
Definition: MDB2.php:2051
__call($method, $params)
Calls a module method using the __call magic method.
Definition: MDB2.php:1920
inTransaction($ignore_nested=false)
If a transaction is currently open.
Definition: MDB2.php:2024
getConnection()
Returns a native connection.
Definition: MDB2.php:1744
& standaloneQuery($query, $types=null, $is_manip=false)
execute a query as database administrator
Definition: MDB2.php:2371
subSelect($query, $type=false)
simple subselect emulation: leaves the query untouched for all RDBMS that support subselects
Definition: MDB2.php:2680
getNestedTransactionError()
The first error that occured since the transaction start.
Definition: MDB2.php:2197
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:3314
resetWarnings()
reset the warning array
Definition: MDB2.php:1471
debug($message, $scope='', $context=array())
set a debug message
Definition: MDB2.php:1593
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:3214
getDatabase()
Get the current database.
Definition: MDB2.php:2289
escape($text, $escape_wildcards=false)
Quotes a string so it can be safely used in a query.
Definition: MDB2.php:1636
compareDefinition($current, $previous)
Obtain an array of changes that may need to applied.
Definition: MDB2.php:3068
completeNestedTransaction($force_rollback=false)
Finish a nested transaction by rolling back if an error occured or committing otherwise.
Definition: MDB2.php:2110
getSequenceName($sqn)
adds sequence name formatting to a sequence name
Definition: MDB2.php:3113
& query($query, $types=null, $result_class=true, $result_wrap_class=false)
Send a query to the database and return any results.
Definition: MDB2.php:2513
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:3170
_affectedRows($connection, $result=null)
Returns the number of rows affected.
Definition: MDB2.php:2458
& _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:2552
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
Definition: MDB2.php:2430
replace($table, $fields)
Execute a SQL REPLACE query.
Definition: MDB2.php:2771
errorInfo($error=null)
This method is used to collect information about an error.
Definition: MDB2.php:1381
rollback($savepoint=null)
Cancel any database changes done during a transaction or since a specific savepoint that is in progre...
Definition: MDB2.php:2003
_modifyQuery($query, $is_manip, $limit, $offset)
Changes a query string for various DBMS specific reasons.
Definition: MDB2.php:2411
supports($feature)
Tell whether a DB implementation or its backend extension supports a given feature.
Definition: MDB2.php:3092
setCharset($charset, $connection=null)
Set the charset on the current connection.
Definition: MDB2.php:2227
currID($seq_name)
Returns the current id of a sequence.
Definition: MDB2.php:3188
__toString()
String conversation.
Definition: MDB2.php:1359
nextID($seq_name, $ondemand=true)
Returns the next free id of a sequence.
Definition: MDB2.php:3150
getDeclaration($type, $name, $field)
Obtain DBMS specific SQL code portion needed to declare of the given type.
Definition: MDB2.php:3046
beginNestedTransaction()
Start a nested transaction.
Definition: MDB2.php:2074
& loadModule($module, $property=null, $phptype_specific=null)
loads a module
Definition: MDB2.php:1851
getWarnings()
Get all warnings in reverse order.
Definition: MDB2.php:1488
setFetchMode($fetchmode, $object_class='stdClass')
Sets which fetch mode should be used by default on queries on this connection.
Definition: MDB2.php:1515
setOption($option, $value)
set the option for the db class
Definition: MDB2.php:1545
setDSN($dsn)
set the DSN
Definition: MDB2.php:2306
getServerVersion($native=false)
return version information about the server
Definition: MDB2.php:2623
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:3245
setDatabase($name)
Select a different database.
Definition: MDB2.php:2271
setLimit($limit, $offset=null)
set the range of the next query
Definition: MDB2.php:2642
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is used to communicate an error and invoke error callbacks etc.
Definition: MDB2.php:1412
quoteIdentifier($str, $check_option=false)
Quote a string so it can be safely used as a table or column name.
Definition: MDB2.php:1711
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:3275
escapePattern($text)
Quotes pattern (% and _) characters in a string)
Definition: MDB2.php:1663
& exec($query)
Execute a manipulation query to the database and return the number of affected rows.
Definition: MDB2.php:2476
_skipDelimitedStrings($query, $position, $p_position)
Utility method, used by prepare() to avoid replacing placeholders within delimited strings.
Definition: MDB2.php:2974
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:3020
commit($savepoint=null)
Commit the database changes done during a transaction that is in progress or release a savepoint.
Definition: MDB2.php:1982
MDB2_Driver_Common()
PHP 4 Constructor.
Definition: MDB2.php:1315
free()
Free the internal references so that the instance can be destroyed.
Definition: MDB2.php:1342
failNestedTransaction($error=null, $immediately=false)
Force setting nested transaction to failed.
Definition: MDB2.php:2167
getOption($option)
Returns the value of an option.
Definition: MDB2.php:1567
getDebugOutput()
output debug info
Definition: MDB2.php:1617
getIndexName($idx)
adds index name formatting to a index name
Definition: MDB2.php:3131
getAsKeyword()
Gets the string to alias column.
Definition: MDB2.php:1728
& prepare($query, $types=null, $result_types=null, $lobs=array())
Prepares a query for multiple execution with execute().
Definition: MDB2.php:2866
getDSN($type='string', $hidepw=false)
return the DSN as a string
Definition: MDB2.php:2331
__construct()
Constructor.
Definition: MDB2.php:1301
connect()
Connect to the database.
Definition: MDB2.php:2210
__destruct()
Destructor.
Definition: MDB2.php:1327
beginTransaction($savepoint=null)
Start a transaction or set a savepoint.
Definition: MDB2.php:1961
_fixResultArrayValues(&$row, $mode)
Do all necessary conversions on result arrays to fix DBMS quirks.
Definition: MDB2.php:1766
__construct($code=MDB2_ERROR, $mode=PEAR_ERROR_RETURN, $level=E_USER_NOTICE, $debuginfo=null)
MDB2_Error constructor.
Definition: MDB2.php:971
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4244
__construct($db_index)
Constructor.
Definition: MDB2.php:4218
MDB2_Module_Common($db_index)
PHP 4 Constructor.
Definition: MDB2.php:4229
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
Definition: MDB2.php:3484
execute($a_data=null)
Definition: MDB2.php:3845
fetchOne($colnum=0, $rownum=null)
fetch single column from the next row from a result set
Definition: MDB2.php:3504
__construct($db, $result, $limit=0, $offset=0)
Constructor.
Definition: MDB2.php:3374
getResource()
return the resource associated with the result object
Definition: MDB2.php:3761
rowCount()
Returns the actual row number that was last fetched (count from 0)
Definition: MDB2.php:3647
MDB2_Result_Common($db, $result, $limit=0, $offset=0)
PHP 4 Constructor.
Definition: MDB2.php:3403
bindColumn($column, &$value, $type=null)
Set bind variable to a column.
Definition: MDB2.php:3780
getColumnNames($flip=false)
Retrieve the names of columns returned by the DBMS in a query result or from the cache.
Definition: MDB2.php:3700
numRows()
Returns the number of rows in a result object.
Definition: MDB2.php:3662
nextResult()
Move the internal result pointer to the next available result.
Definition: MDB2.php:3678
setResultTypes($types)
Define the list of types to be associated with the columns of a given result set.
Definition: MDB2.php:3432
fetch($fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
Definition: MDB2.php:3383
free()
Free the internal resources associated with result.
Definition: MDB2.php:3833
_assignBindColumns($row)
Bind a variable to a value in the result row.
Definition: MDB2.php:3812
_getColumnNames()
Retrieve the names of columns returned by the DBMS in a query result.
Definition: MDB2.php:3728
numCols()
Count the number of columns returned by the DBMS in a query result.
Definition: MDB2.php:3745
seek($rownum=0)
Seek to a specific row in a result set.
Definition: MDB2.php:3458
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:3576
fetchCol($colnum=0)
Fetch and return a column from the current row pointer position.
Definition: MDB2.php:3530
MDB2_Row(&$row)
PHP 4 Constructor.
Definition: MDB2.php:3888
__construct(&$row)
constructor
Definition: MDB2.php:3873
bindParamArray(&$values, $types=null)
Bind the variables of multiple a parameter of a prepared query in bulk.
Definition: MDB2.php:4059
bindValue($parameter, $value, $type=null)
Set the value of a parameter of a prepared query.
Definition: MDB2.php:3966
bindValueArray($values, $types=null)
Set the values of multiple a parameter of a prepared query in bulk.
Definition: MDB2.php:3998
& _execute($result_class=true, $result_wrap_class=false)
Execute a prepared query statement helper method.
Definition: MDB2.php:4120
& execute($values=null, $result_class=true, $result_wrap_class=false)
Execute a prepared query statement.
Definition: MDB2.php:4088
MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip=false, $limit=null, $offset=null)
PHP 4 Constructor.
Definition: MDB2.php:3945
bindParam($parameter, &$value, $type=null)
Bind a variable to a parameter of a prepared query.
Definition: MDB2.php:4027
__construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip=false, $limit=null, $offset=null)
Constructor.
Definition: MDB2.php:3926
free()
Release resources allocated for the specified prepared query.
Definition: MDB2.php:4166
isStatement($value)
Tell whether a value is a MDB2 statement interface.
Definition: MDB2.php:677
fileExists($file)
Checks if a file exists in the include path.
Definition: MDB2.php:926
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
classExists($classname)
Checks if a class exists without triggering __autoload.
Definition: MDB2.php:309
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
Definition: MDB2.php:660
isResult($value)
Tell whether a value is a MDB2 result.
Definition: MDB2.php:643
isConnection($value)
Tell whether a value is a MDB2 connection.
Definition: MDB2.php:626
loadFile($file)
load a file (like 'Date')
Definition: MDB2.php:521
parseDSN($dsn)
Definition: MDB2.php:796
errorMessage($value=null)
Return a textual error message for a MDB2 error code.
Definition: MDB2.php:697
loadClass($class_name, $debug)
Loads a PEAR class.
Definition: MDB2.php:330
apiVersion()
Return the MDB2 API version.
Definition: MDB2.php:545
setOptions(&$db, $options)
set option array in an exiting database object
Definition: MDB2.php:284
& 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
& 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
& singleton($dsn=null, $options=false)
Returns a MDB2 connection with the requested DSN.
Definition: MDB2.php:486
$_default_error_mode
Definition: PEAR.php:120
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
$_default_error_options
Definition: PEAR.php:129
& 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's de...
Definition: PEAR.php:522
Class ilDatabaseException.
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19
$code
Definition: example_050.php:99
Interface ilDBStatement.
$error
Definition: Error.php:17
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
$info
Definition: index.php:5
$debug
Definition: loganalyzer.php:16
$keys
if($modEnd===false) $module
Definition: module.php:59
The main 'MDB2' class is simply a container class with some static methods for creating DB objects as...
$query
$type
if(empty($password)) $table
Definition: pwgen.php:24
$insert
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
foreach($_POST as $key=> $value) $res
$params
Definition: disable.php:11
$text
Definition: errorreport.php:18