55 require_once
'PEAR.php';
67 define(
'MDB2_OK',
true);
68 define(
'MDB2_ERROR', -1);
69 define(
'MDB2_ERROR_SYNTAX', -2);
70 define(
'MDB2_ERROR_CONSTRAINT', -3);
71 define(
'MDB2_ERROR_NOT_FOUND', -4);
72 define(
'MDB2_ERROR_ALREADY_EXISTS', -5);
73 define(
'MDB2_ERROR_UNSUPPORTED', -6);
74 define(
'MDB2_ERROR_MISMATCH', -7);
75 define(
'MDB2_ERROR_INVALID', -8);
76 define(
'MDB2_ERROR_NOT_CAPABLE', -9);
77 define(
'MDB2_ERROR_TRUNCATED', -10);
78 define(
'MDB2_ERROR_INVALID_NUMBER', -11);
79 define(
'MDB2_ERROR_INVALID_DATE', -12);
80 define(
'MDB2_ERROR_DIVZERO', -13);
81 define(
'MDB2_ERROR_NODBSELECTED', -14);
82 define(
'MDB2_ERROR_CANNOT_CREATE', -15);
83 define(
'MDB2_ERROR_CANNOT_DELETE', -16);
84 define(
'MDB2_ERROR_CANNOT_DROP', -17);
85 define(
'MDB2_ERROR_NOSUCHTABLE', -18);
86 define(
'MDB2_ERROR_NOSUCHFIELD', -19);
87 define(
'MDB2_ERROR_NEED_MORE_DATA', -20);
88 define(
'MDB2_ERROR_NOT_LOCKED', -21);
89 define(
'MDB2_ERROR_VALUE_COUNT_ON_ROW', -22);
90 define(
'MDB2_ERROR_INVALID_DSN', -23);
91 define(
'MDB2_ERROR_CONNECT_FAILED', -24);
92 define(
'MDB2_ERROR_EXTENSION_NOT_FOUND',-25);
93 define(
'MDB2_ERROR_NOSUCHDB', -26);
94 define(
'MDB2_ERROR_ACCESS_VIOLATION', -27);
95 define(
'MDB2_ERROR_CANNOT_REPLACE', -28);
96 define(
'MDB2_ERROR_CONSTRAINT_NOT_NULL',-29);
97 define(
'MDB2_ERROR_DEADLOCK', -30);
98 define(
'MDB2_ERROR_CANNOT_ALTER', -31);
99 define(
'MDB2_ERROR_MANAGER', -32);
100 define(
'MDB2_ERROR_MANAGER_PARSE', -33);
101 define(
'MDB2_ERROR_LOADMODULE', -34);
102 define(
'MDB2_ERROR_INSUFFICIENT_DATA', -35);
109 define(
'MDB2_PREPARE_MANIP',
false);
110 define(
'MDB2_PREPARE_RESULT', null);
119 define(
'MDB2_FETCHMODE_DEFAULT', 0);
124 define(
'MDB2_FETCHMODE_ORDERED', 1);
129 define(
'MDB2_FETCHMODE_ASSOC', 2);
134 define(
'MDB2_FETCHMODE_OBJECT', 3);
142 define(
'MDB2_FETCHMODE_FLIPPED', 4);
151 define(
'MDB2_PORTABILITY_NONE', 0);
158 define(
'MDB2_PORTABILITY_FIX_CASE', 1);
164 define(
'MDB2_PORTABILITY_RTRIM', 2);
170 define(
'MDB2_PORTABILITY_DELETE_COUNT', 4);
176 define(
'MDB2_PORTABILITY_NUMROWS', 8);
191 define(
'MDB2_PORTABILITY_ERRORS', 16);
198 define(
'MDB2_PORTABILITY_EMPTY_TO_NULL', 32);
204 define(
'MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES', 64);
210 define(
'MDB2_PORTABILITY_ALL', 127);
282 foreach (
$options as $option => $value) {
283 $test = $db->setOption($option, $value);
306 if (version_compare(phpversion(),
"5.0",
">=")) {
307 return class_exists($classname,
false);
309 return class_exists($classname);
328 $file_name = str_replace(
'_', DIRECTORY_SEPARATOR, $class_name).
'.php';
330 $include = include_once($file_name);
332 $include = @include_once($file_name);
336 $msg =
"unable to find package '$class_name' file '$file_name'";
338 $msg =
"unable to load class '$class_name' from file '$file_name'";
377 if (empty($dsninfo[
'phptype'])) {
379 null, null,
'no RDBMS driver specified');
382 $class_name =
'MDB2_Driver_'.$dsninfo[
'phptype'];
384 $debug = (!empty(
$options[
'debug']));
390 $db =&
new $class_name();
391 $db->setDSN($dsninfo);
438 $err = $db->connect();
440 $dsn = $db->getDSN(
'string',
'xxx');
442 $err->addUserInfo($dsn);
485 $dsninfo = array_merge(
$GLOBALS[
'_MDB2_dsninfo_default'], $dsninfo);
486 $keys = array_keys(
$GLOBALS[
'_MDB2_databases']);
487 for ($i=0, $j=count($keys); $i<$j; ++$i) {
488 if (isset(
$GLOBALS[
'_MDB2_databases'][$keys[$i]])) {
489 $tmp_dsn =
$GLOBALS[
'_MDB2_databases'][$keys[$i]]->getDSN(
'array');
490 if (count(array_diff_assoc($tmp_dsn, $dsninfo)) == 0) {
492 return $GLOBALS[
'_MDB2_databases'][$keys[$i]];
496 } elseif (is_array(
$GLOBALS[
'_MDB2_databases']) && reset(
$GLOBALS[
'_MDB2_databases'])) {
518 $file_name =
'MDB2'.DIRECTORY_SEPARATOR.$file.
'.php';
521 'unable to find: '.$file_name);
523 if (!include_once($file_name)) {
525 'unable to load driver class: '.$file_name);
596 if (is_a(
$data,
'MDB2_Error')) {
597 if (is_null($code)) {
599 } elseif (is_string($code)) {
600 return $data->getMessage() === $code;
602 $code = (array)$code;
603 return in_array(
$data->getCode(), $code);
623 return is_a($value,
'MDB2_Driver_Common');
640 return is_a($value,
'MDB2_Result');
657 return is_a($value,
'MDB2_Result_Common');
674 return is_a($value,
'MDB2_Statement');
694 static $errorMessages;
696 if (is_array($value)) {
697 $errorMessages = $value;
701 if (!isset($errorMessages)) {
702 $errorMessages = array(
739 if (is_null($value)) {
740 return $errorMessages;
744 $value = $value->getCode();
747 return isset($errorMessages[$value]) ?
748 $errorMessages[$value] : $errorMessages[
MDB2_ERROR];
793 $parsed =
$GLOBALS[
'_MDB2_dsninfo_default'];
795 if (is_array($dsn)) {
796 $dsn = array_merge($parsed, $dsn);
797 if (!$dsn[
'dbsyntax']) {
798 $dsn[
'dbsyntax'] = $dsn[
'phptype'];
804 if (($pos = strpos($dsn,
'://')) !==
false) {
805 $str = substr($dsn, 0, $pos);
806 $dsn = substr($dsn, $pos + 3);
814 if (preg_match(
'|^(.+?)\((.*?)\)$|', $str, $arr)) {
815 $parsed[
'phptype'] = $arr[1];
816 $parsed[
'dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
818 $parsed[
'phptype'] = $str;
819 $parsed[
'dbsyntax'] = $str;
828 if (($at = strrpos($dsn,
'@')) !==
false) {
829 $str = substr($dsn, 0, $at);
830 $dsn = substr($dsn, $at + 1);
831 if (($pos = strpos($str,
':')) !==
false) {
832 $parsed[
'username'] = rawurldecode(substr($str, 0, $pos));
833 $parsed[
'password'] = rawurldecode(substr($str, $pos + 1));
835 $parsed[
'username'] = rawurldecode($str);
842 if (preg_match(
'|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
844 $proto_opts = $match[2] ? $match[2] :
false;
849 if (strpos($dsn,
'+') !==
false) {
850 list($proto, $dsn) = explode(
'+', $dsn, 2);
852 if ( strpos($dsn,
'//') === 0
853 && strpos($dsn,
'/', 2) !==
false 854 && $parsed[
'phptype'] ==
'oci8' 861 } elseif (strpos($dsn,
'/') !==
false) {
862 list($proto_opts, $dsn) = explode(
'/', $dsn, 2);
870 $parsed[
'protocol'] = (!empty($proto)) ? $proto :
'tcp';
871 $proto_opts = rawurldecode($proto_opts);
872 if (strpos($proto_opts,
':') !==
false) {
873 list($proto_opts, $parsed[
'port']) = explode(
':', $proto_opts);
875 if ($parsed[
'protocol'] ==
'tcp') {
876 $parsed[
'hostspec'] = $proto_opts;
877 } elseif ($parsed[
'protocol'] ==
'unix') {
878 $parsed[
'socket'] = $proto_opts;
885 if (($pos = strpos($dsn,
'?')) ===
false) {
886 $parsed[
'database'] = $dsn;
889 $parsed[
'database'] = substr($dsn, 0, $pos);
890 $dsn = substr($dsn, $pos + 1);
891 if (strpos($dsn,
'&') !==
false) {
892 $opts = explode(
'&', $dsn);
896 foreach ($opts as $opt) {
897 list($key, $value) = explode(
'=', $opt);
898 if (!isset($parsed[$key])) {
900 $parsed[$key] = rawurldecode($value);
924 if (!@ini_get(
'safe_mode')) {
925 $dirs = explode(PATH_SEPARATOR, ini_get(
'include_path'));
926 foreach (
$dirs as $dir) {
927 if (@is_readable($dir . DIRECTORY_SEPARATOR .
$file)) {
932 $fp = @fopen(
$file,
'r',
true);
933 if (is_resource($fp)) {
967 $level = E_USER_NOTICE, $debuginfo = null)
969 if (is_null($code)) {
973 $mode, $level, $debuginfo);
1012 var $connected_dsn = array();
1019 var $connection = 0;
1033 var $database_name =
'';
1040 var $connected_database_name =
'';
1047 var $connected_server_info =
'';
1054 var $supported = array(
1055 'sequences' =>
false,
1057 'affected_rows' =>
false,
1058 'summary_functions' =>
false,
1059 'order_by_text' =>
false,
1060 'transactions' =>
false,
1061 'savepoints' =>
false,
1062 'current_id' =>
false,
1063 'limit_queries' =>
false,
1066 'sub_selects' =>
false,
1067 'auto_increment' =>
false,
1068 'primary_key' =>
false,
1069 'result_introspection' =>
false,
1070 'prepared_statements' =>
false,
1071 'identifier_quoting' =>
false,
1072 'pattern_escaping' =>
false,
1073 'new_link' =>
false,
1124 'field_case' => CASE_LOWER,
1125 'disable_query' =>
false,
1126 'result_class' =>
'MDB2_Result_%s',
1127 'buffered_result_class' =>
'MDB2_BufferedResult_%s',
1128 'result_wrap_class' =>
false,
1129 'result_buffering' =>
true,
1130 'fetch_class' =>
'stdClass',
1131 'persistent' =>
false,
1133 'debug_handler' =>
'MDB2_defaultDebugOutput',
1134 'debug_expanded_output' =>
false,
1135 'default_text_field_length' => 4096,
1136 'lob_buffer_length' => 8192,
1137 'log_line_break' =>
"\n",
1138 'idxname_format' =>
'%s_idx',
1139 'seqname_format' =>
'%s_seq',
1140 'savepoint_format' =>
'MDB2_SAVEPOINT_%s',
1141 'statement_format' =>
'MDB2_STATEMENT_%1$s_%2$s',
1142 'seqcol_name' =>
'sequence',
1143 'quote_identifier' =>
false,
1144 'use_transactions' =>
true,
1145 'decimal_places' => 2,
1155 'emulate_prepared' =>
false,
1156 'datatype_map' => array(),
1157 'datatype_map_callback' => array(),
1158 'nativetype_map_callback' => array(),
1166 var $string_quoting = array(
'start' =>
"'",
'end' =>
"'",
'escape' =>
false,
'escape_pattern' =>
false);
1173 var $identifier_quoting = array(
'start' =>
'"',
'end' =>
'"',
'escape' =>
'"');
1180 var $sql_comments = array(
1181 array(
'start' =>
'--',
'end' =>
"\n",
'escape' =>
false),
1182 array(
'start' =>
'/*',
'end' =>
'*/',
'escape' =>
false),
1190 var $wildcards = array(
'%',
'_');
1197 var $as_keyword =
' AS ';
1204 var $warnings = array();
1211 var $debug_output =
'';
1218 var $in_transaction =
false;
1225 var $nested_transaction_counter = null;
1232 var $has_transaction_error =
false;
1281 var $modules = array();
1288 var $destructor_registered =
true;
1299 $db_index = key(
$GLOBALS[
'_MDB2_databases']) + 1;
1300 $GLOBALS[
'_MDB2_databases'][$db_index] = &$this;
1301 $this->db_index = $db_index;
1312 $this->destructor_registered =
false;
1313 $this->__construct();
1324 $this->disconnect(
false);
1339 unset(
$GLOBALS[
'_MDB2_databases'][$this->db_index]);
1340 unset($this->db_index);
1356 $info = get_class($this);
1357 $info.=
': (phptype = '.$this->phptype.
', dbsyntax = '.$this->dbsyntax.
')';
1358 if ($this->connection) {
1359 $info.=
' [connected]';
1378 return array($error, null, null);
1407 function &
raiseError($code = null, $mode = null, $options = null, $userinfo = null, $method = null)
1409 $userinfo =
"[Error message: $userinfo]\n";
1414 if (is_null($mode) && !empty($this->_default_error_mode)) {
1415 $mode = $this->_default_error_mode;
1416 $options = $this->_default_error_options;
1418 if (is_null($userinfo)) {
1419 $userinfo = $code->getUserinfo();
1421 $code = $code->getCode();
1425 } elseif (isset($this->connection)) {
1426 if (!empty($this->last_query)) {
1427 $userinfo.=
"[Last executed query: {$this->last_query}]\n";
1429 $native_errno = $native_msg = null;
1430 list($code, $native_errno, $native_msg) = $this->errorInfo($code);
1431 if (!is_null($native_errno) && $native_errno !==
'') {
1432 $userinfo.=
"[Native code: $native_errno]\n";
1434 if (!is_null($native_msg) && $native_msg !==
'') {
1435 $userinfo.=
"[Native message: ". strip_tags($native_msg) .
"]\n";
1437 if (!is_null($method)) {
1438 $userinfo = $method.
': '.$userinfo;
1442 $err =&
PEAR::raiseError(null, $code, $mode, $options, $userinfo,
'MDB2_Error',
true);
1444 && isset($this->nested_transaction_counter) && !$this->has_transaction_error) {
1445 $this->has_transaction_error =& $err;
1462 $this->warnings = array();
1479 return array_reverse($this->warnings);
1506 switch ($fetchmode) {
1508 $this->options[
'fetch_class'] = $object_class;
1511 $this->fetchmode = $fetchmode;
1515 'invalid fetchmode mode', __FUNCTION__);
1536 if (array_key_exists($option, $this->options)) {
1537 $this->options[$option] = $value;
1541 "unknown option $option", __FUNCTION__);
1558 if (array_key_exists($option, $this->options)) {
1559 return $this->options[$option];
1562 "unknown option $option", __FUNCTION__);
1582 function debug($message, $scope =
'', $context = array())
1584 if ($this->options[
'debug'] && $this->options[
'debug_handler']) {
1585 if (!$this->options[
'debug_expanded_output']) {
1586 if (!empty($context[
'when']) && $context[
'when'] !==
'pre') {
1589 $context = empty($context[
'is_manip']) ? false : $context[
'is_manip'];
1591 return call_user_func_array($this->options[
'debug_handler'], array(&$this, $scope, $message, $context));
1608 return $this->debug_output;
1625 function escape($text, $escape_wildcards =
false)
1627 if ($escape_wildcards) {
1628 $text = $this->escapePattern($text);
1631 $text = str_replace($this->string_quoting[
'end'], $this->string_quoting[
'escape'] . $this->string_quoting[
'end'], $text);
1654 if ($this->string_quoting[
'escape_pattern']) {
1655 $text = str_replace($this->string_quoting[
'escape_pattern'], $this->string_quoting[
'escape_pattern'] . $this->string_quoting[
'escape_pattern'], $text);
1656 foreach ($this->wildcards as $wildcard) {
1657 $text = str_replace($wildcard, $this->string_quoting[
'escape_pattern'] . $wildcard, $text);
1702 if ($check_option && !$this->options[
'quote_identifier']) {
1705 $str = str_replace($this->identifier_quoting[
'end'], $this->identifier_quoting[
'escape'] . $this->identifier_quoting[
'end'], $str);
1706 return $this->identifier_quoting[
'start'] . $str . $this->identifier_quoting[
'end'];
1719 return $this->as_keyword;
1739 return $this->connection;
1759 foreach (
$row as $key => $value) {
1760 if ($value ===
'') {
1766 foreach (
$row as $key => $value) {
1767 if (is_string($value)) {
1768 $row[$key] = rtrim($value);
1774 foreach (
$row as $key => $value) {
1775 $tmp_row[preg_replace(
'/^(?:.*\.)?([^.]+)$/',
'\\1', $key)] = $value;
1780 foreach (
$row as $key => $value) {
1781 if ($value ===
'') {
1783 } elseif (is_string($value)) {
1784 $row[$key] = rtrim($value);
1790 foreach (
$row as $key => $value) {
1791 if (is_string($value)) {
1792 $value = rtrim($value);
1794 $tmp_row[preg_replace(
'/^(?:.*\.)?([^.]+)$/',
'\\1', $key)] = $value;
1800 foreach (
$row as $key => $value) {
1801 if ($value ===
'') {
1804 $tmp_row[preg_replace(
'/^(?:.*\.)?([^.]+)$/',
'\\1', $key)] = $value;
1810 foreach (
$row as $key => $value) {
1811 if ($value ===
'') {
1813 } elseif (is_string($value)) {
1814 $value = rtrim($value);
1816 $tmp_row[preg_replace(
'/^(?:.*\.)?([^.]+)$/',
'\\1', $key)] = $value;
1840 function &
loadModule($module, $property = null, $phptype_specific = null)
1843 $property = strtolower($module);
1846 if (!isset($this->{$property})) {
1847 $version = $phptype_specific;
1848 if ($phptype_specific !==
false) {
1850 $class_name =
'MDB2_Driver_'.$module.
'_'.$this->phptype;
1851 $file_name = str_replace(
'_', DIRECTORY_SEPARATOR, $class_name).
'.php';
1853 if ($phptype_specific ===
false 1857 $class_name =
'MDB2_'.$module;
1858 $file_name = str_replace(
'_', DIRECTORY_SEPARATOR, $class_name).
'.php';
1868 if (method_exists($class_name,
'getClassName')) {
1869 $class_name_new = call_user_func(array($class_name,
'getClassName'), $this->db_index);
1870 if ($class_name != $class_name_new) {
1871 $class_name = $class_name_new;
1882 "unable to load module '$module' into property '$property'", __FUNCTION__);
1885 $this->{$property} =&
new $class_name($this->db_index);
1886 $this->modules[$module] =& $this->{$property};
1891 $this->loaded_version_modules[] = $property;
1895 return $this->{$property};
1912 if (preg_match(
'/^([a-z]+)([A-Z])(.*)$/', $method, $match)
1913 && isset($this->options[
'modules'][$match[1]])
1915 $module = $this->options[
'modules'][$match[1]];
1916 $method = strtolower($match[2]).$match[3];
1917 if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) {
1918 $result =& $this->loadModule($module);
1924 foreach ($this->modules as $key => $foo) {
1925 if (is_object($this->modules[$key])
1926 && method_exists($this->modules[$key], $method)
1933 if (!is_null($module)) {
1934 return call_user_func_array(array(&$this->modules[$module], $method), $params);
1936 trigger_error(sprintf(
'Call to undefined function: %s::%s().', get_class($this), $method), E_USER_ERROR);
1952 $this->debug(
'Starting transaction', __FUNCTION__, array(
'is_manip' =>
true,
'savepoint' => $savepoint));
1954 'transactions are not supported', __FUNCTION__);
1973 $this->debug(
'Committing transaction/savepoint', __FUNCTION__, array(
'is_manip' =>
true,
'savepoint' => $savepoint));
1975 'commiting transactions is not supported', __FUNCTION__);
1994 $this->debug(
'Rolling back transaction/savepoint', __FUNCTION__, array(
'is_manip' =>
true,
'savepoint' => $savepoint));
1996 'rolling back transactions is not supported', __FUNCTION__);
2015 if (!$ignore_nested && isset($this->nested_transaction_counter)) {
2016 return $this->nested_transaction_counter;
2018 return $this->in_transaction;
2042 $this->debug(
'Setting transaction isolation level', __FUNCTION__, array(
'is_manip' =>
true));
2044 'isolation level setting is not supported', __FUNCTION__);
2065 if ($this->in_transaction) {
2066 ++$this->nested_transaction_counter;
2067 $savepoint = sprintf($this->options[
'savepoint_format'], $this->nested_transaction_counter);
2068 if ($this->supports(
'savepoints') && $savepoint) {
2069 return $this->beginTransaction($savepoint);
2073 $this->has_transaction_error =
false;
2074 $result = $this->beginTransaction();
2075 $this->nested_transaction_counter = 1;
2101 if ($this->nested_transaction_counter > 1) {
2102 $savepoint = sprintf($this->options[
'savepoint_format'], $this->nested_transaction_counter);
2103 if ($this->supports(
'savepoints') && $savepoint) {
2104 if ($force_rollback || $this->has_transaction_error) {
2105 $result = $this->rollback($savepoint);
2108 $this->has_transaction_error =
false;
2111 $result = $this->commit($savepoint);
2116 --$this->nested_transaction_counter;
2120 $this->nested_transaction_counter = null;
2124 if ($this->in_transaction) {
2125 if ($force_rollback || $this->has_transaction_error) {
2134 $this->has_transaction_error =
false;
2158 if (is_null($error)) {
2159 $error = $this->has_transaction_error ? $this->has_transaction_error :
true;
2160 } elseif (!$error) {
2163 $this->has_transaction_error = $error;
2164 if (!$immediately) {
2167 return $this->rollback();
2188 return $this->has_transaction_error;
2202 'method not implemented', __FUNCTION__);
2219 'method not implemented', __FUNCTION__);
2238 $this->connection = 0;
2239 $this->connected_dsn = array();
2240 $this->connected_database_name =
'';
2241 $this->opened_persistent = null;
2242 $this->connected_server_info =
'';
2243 $this->in_transaction = null;
2244 $this->nested_transaction_counter = null;
2262 $previous_database_name = (isset($this->database_name)) ? $this->database_name :
'';
2263 $this->database_name = $name;
2264 $this->disconnect(
false);
2265 return $previous_database_name;
2280 return $this->database_name;
2297 $dsn_default =
$GLOBALS[
'_MDB2_dsninfo_default'];
2299 if (array_key_exists(
'database', $dsn)) {
2300 $this->database_name = $dsn[
'database'];
2301 unset($dsn[
'database']);
2303 $this->dsn = array_merge($dsn_default, $dsn);
2304 return $this->disconnect(
false);
2320 function getDSN($type =
'string', $hidepw =
false)
2322 $dsn = array_merge(
$GLOBALS[
'_MDB2_dsninfo_default'], $this->dsn);
2323 $dsn[
'phptype'] = $this->phptype;
2324 $dsn[
'database'] = $this->database_name;
2326 $dsn[
'password'] = $hidepw;
2331 $dsn = $dsn[
'phptype'].
2332 ($dsn[
'dbsyntax'] ? (
'('.$dsn[
'dbsyntax'].
')') :
'').
2333 '://'.$dsn[
'username'].
':'.
2334 $dsn[
'password'].
'@'.$dsn[
'hostspec'].
2335 ($dsn[
'port'] ? (
':'.$dsn[
'port']) :
'').
2336 '/'.$dsn[
'database'];
2362 $offset = $this->offset;
2363 $limit = $this->limit;
2364 $this->offset = $this->limit = 0;
2365 $query = $this->_modifyQuery(
$query, $is_manip, $limit, $offset);
2367 $connection = $this->getConnection();
2372 $result =& $this->_doQuery(
$query, $is_manip, $connection,
false);
2378 $affected_rows = $this->_affectedRows($connection,
$result);
2379 return $affected_rows;
2381 $result =& $this->_wrapResult(
$result, $types,
true,
false, $limit, $offset);
2419 function &
_doQuery(
$query, $is_manip =
false, $connection = null, $database_name = null)
2421 $this->last_query =
$query;
2422 $result = $this->debug(
$query,
'query', array(
'is_manip' => $is_manip,
'when' =>
'pre'));
2430 'method not implemented', __FUNCTION__);
2450 'method not implemented', __FUNCTION__);
2467 $offset = $this->offset;
2468 $limit = $this->limit;
2469 $this->offset = $this->limit = 0;
2470 $query = $this->_modifyQuery(
$query,
true, $limit, $offset);
2472 $connection = $this->getConnection();
2477 $result =& $this->_doQuery(
$query,
true, $connection, $this->database_name);
2482 $affectedRows = $this->_affectedRows($connection,
$result);
2483 return $affectedRows;
2502 function &
query(
$query, $types = null, $result_class =
true, $result_wrap_class =
false)
2504 $offset = $this->offset;
2505 $limit = $this->limit;
2506 $this->offset = $this->limit = 0;
2507 $query = $this->_modifyQuery(
$query,
false, $limit, $offset);
2509 $connection = $this->getConnection();
2514 $result =& $this->_doQuery(
$query,
false, $connection, $this->database_name);
2519 $result =& $this->_wrapResult(
$result, $types, $result_class, $result_wrap_class, $limit, $offset);
2542 $result_wrap_class =
false, $limit = null, $offset = null)
2544 if ($types ===
true) {
2545 if ($this->supports(
'result_introspection')) {
2546 $this->loadModule(
'Reverse', null,
true);
2547 $tableInfo = $this->reverse->tableInfo(
$result);
2552 foreach ($tableInfo as $field) {
2553 $types[] = $field[
'mdb2type'];
2560 if ($result_class ===
true) {
2561 $result_class = $this->options[
'result_buffering']
2562 ? $this->options[
'buffered_result_class'] : $this->options[
'result_class'];
2565 if ($result_class) {
2566 $class_name = sprintf($result_class, $this->phptype);
2569 'result class does not exist '.$class_name, __FUNCTION__);
2575 'result class is not extended from MDB2_Result_Common', __FUNCTION__);
2578 if (!empty($types)) {
2579 $err =
$result->setResultTypes($types);
2586 if ($result_wrap_class ===
true) {
2587 $result_wrap_class = $this->options[
'result_wrap_class'];
2589 if ($result_wrap_class) {
2592 'result wrap class does not exist '.$result_wrap_class, __FUNCTION__);
2615 'method not implemented', __FUNCTION__);
2633 if (!$this->supports(
'limit_queries')) {
2635 'limit is not supported by this driver', __FUNCTION__);
2637 $limit = (int)$limit;
2640 'it was not specified a valid selected range row limit', __FUNCTION__);
2642 $this->limit = $limit;
2643 if (!is_null($offset)) {
2644 $offset = (int)$offset;
2647 'it was not specified a valid first selected range row', __FUNCTION__);
2649 $this->offset = $offset;
2671 if ($this->supports(
'sub_selects') ===
true) {
2675 if (!$this->supports(
'sub_selects')) {
2677 'method not implemented', __FUNCTION__);
2680 $col = $this->queryCol(
$query, $type);
2684 if (!is_array($col) || count($col) == 0) {
2688 $this->loadModule(
'Datatype', null,
true);
2689 return $this->datatype->implodeArray($col, $type);
2691 return implode(
', ', $col);
2762 if (!$this->supports(
'replace')) {
2764 'replace query is not supported', __FUNCTION__);
2766 $count = count($fields);
2767 $condition = $values = array();
2768 for ($colnum = 0, reset($fields); $colnum < $count; next($fields), $colnum++) {
2769 $name = key($fields);
2770 if (isset($fields[$name][
'null']) && $fields[$name][
'null']) {
2773 $type = isset($fields[$name][
'type']) ? $fields[$name][
'type'] : null;
2774 $value = $this->quote($fields[$name][
'value'], $type);
2776 $values[$name] = $value;
2777 if (isset($fields[$name][
'key']) && $fields[$name][
'key']) {
2778 if ($value ===
'NULL') {
2780 'key value '.$name.
' may not be NULL', __FUNCTION__);
2782 $condition[] = $name .
'=' . $value;
2785 if (empty($condition)) {
2787 'not specified which fields are keys', __FUNCTION__);
2791 $in_transaction = $this->in_transaction;
2796 $connection = $this->getConnection();
2801 $condition =
' WHERE '.implode(
' AND ', $condition);
2802 $query =
"DELETE FROM $table$condition";
2805 $affected_rows = $this->_affectedRows($connection,
$result);
2806 $insert = implode(
', ', array_keys($values));
2807 $values = implode(
', ', $values);
2808 $query =
"INSERT INTO $table ($insert) VALUES ($values)";
2811 $affected_rows += $this->_affectedRows($connection,
$result);;
2815 if (!$in_transaction) {
2827 return $affected_rows;
2858 $offset = $this->offset;
2859 $limit = $this->limit;
2860 $this->offset = $this->limit = 0;
2861 $result = $this->debug(
$query, __FUNCTION__, array(
'is_manip' => $is_manip,
'when' =>
'pre'));
2868 $placeholder_type_guess = $placeholder_type = null;
2871 $positions = array();
2873 $ignores = $this->sql_comments;
2874 $ignores[] = $this->string_quoting;
2875 $ignores[] = $this->identifier_quoting;
2876 while ($position < strlen(
$query)) {
2877 $q_position = strpos(
$query, $question, $position);
2878 $c_position = strpos(
$query, $colon, $position);
2879 if ($q_position && $c_position) {
2880 $p_position = min($q_position, $c_position);
2881 } elseif ($q_position) {
2882 $p_position = $q_position;
2883 } elseif ($c_position) {
2884 $p_position = $c_position;
2888 if (is_null($placeholder_type)) {
2889 $placeholder_type_guess =
$query[$p_position];
2892 $new_pos = $this->_skipDelimitedStrings(
$query, $position, $p_position);
2896 if ($new_pos != $position) {
2897 $position = $new_pos;
2901 if (
$query[$position] == $placeholder_type_guess) {
2902 if (is_null($placeholder_type)) {
2903 $placeholder_type =
$query[$p_position];
2904 $question = $colon = $placeholder_type;
2905 if (!empty($types) && is_array($types)) {
2906 if ($placeholder_type ==
':') {
2907 if (is_int(key($types))) {
2908 $types_tmp = $types;
2913 $types = array_values($types);
2917 if ($placeholder_type ==
':') {
2918 $parameter = preg_replace(
'/^.{'.($position+1).
'}([a-z0-9_]+).*$/si',
'\\1',
$query);
2919 if ($parameter ===
'') {
2921 'named parameter with an empty name', __FUNCTION__);
2924 $positions[$p_position] = $parameter;
2925 $query = substr_replace(
$query,
'?', $position, strlen($parameter)+1);
2927 if (isset($count) && isset($types_tmp[++$count])) {
2928 $types[$parameter] = $types_tmp[$count];
2931 $positions[$p_position] = count($positions);
2933 $position = $p_position + 1;
2935 $position = $p_position;
2938 $class_name =
'MDB2_Statement_'.$this->phptype;
2940 $obj =&
new $class_name($this, $statement, $positions,
$query, $types, $result_types, $is_manip, $limit, $offset);
2941 $this->debug(
$query, __FUNCTION__, array(
'is_manip' => $is_manip,
'when' =>
'post',
'result' => $obj));
2965 $ignores = $this->sql_comments;
2966 $ignores[] = $this->string_quoting;
2967 $ignores[] = $this->identifier_quoting;
2969 foreach ($ignores as
$ignore) {
2970 if (!empty($ignore[
'start'])) {
2971 if (is_int($start_quote = strpos(
$query, $ignore[
'start'], $position)) && $start_quote < $p_position) {
2972 $end_quote = $start_quote;
2974 if (!is_int($end_quote = strpos(
$query, $ignore[
'end'], $end_quote + 1))) {
2975 if ($ignore[
'end'] ===
"\n") {
2976 $end_quote = strlen(
$query) - 1;
2979 'query with an unterminated text string specified', __FUNCTION__);
2983 }
while ($ignore[
'escape'] &&
$query[($end_quote - 1)] == $ignore[
'escape']);
2984 $position = $end_quote + 1;
3009 function quote($value, $type = null, $quote =
true, $escape_wildcards =
false)
3011 $result = $this->loadModule(
'Datatype', null,
true);
3016 return $this->datatype->quote($value, $type, $quote, $escape_wildcards);
3037 $result = $this->loadModule(
'Datatype', null,
true);
3041 return $this->datatype->getDeclaration($type, $name, $field);
3059 $result = $this->loadModule(
'Datatype', null,
true);
3063 return $this->datatype->compareDefinition($current, $previous);
3083 if (array_key_exists($feature, $this->supported)) {
3084 return $this->supported[$feature];
3087 "unknown support feature $feature", __FUNCTION__);
3104 return sprintf($this->options[
'seqname_format'],
3105 preg_replace(
'/[^a-z0-9_\$.]/i',
'_', $sqn));
3122 return sprintf($this->options[
'idxname_format'],
3123 preg_replace(
'/[^a-z0-9_\$]/i',
'_', $idx));
3142 'method not implemented', __FUNCTION__);
3162 'method not implemented', __FUNCTION__);
3179 $this->warnings[] =
'database does not support getting current 3180 sequence value, the sequence value was incremented';
3181 return $this->nextID($seq_name);
3210 $one =
$result->fetchOne($colnum);
3271 $col =
$result->fetchCol($colnum);
3304 $rekey =
false, $force_array =
false, $group =
false)
3311 $all =
$result->fetchAll($fetchmode, $rekey, $force_array, $group);
3350 var $types = array();
3351 var $values = array();
3353 var $offset_count = 0;
3367 $this->offset = $offset;
3368 $this->limit = max(0, $limit - 1);
3379 $this->__construct($db, $result, $limit, $offset);
3408 $load = $this->db->loadModule(
'Datatype', null,
true);
3412 $types = $this->db->datatype->checkResultTypes($types);
3416 $this->types = $types;
3434 $target_rownum = $rownum - 1;
3435 if ($this->rownum > $target_rownum) {
3437 'seeking to previous rows not implemented', __FUNCTION__);
3439 while ($this->rownum < $target_rownum) {
3461 'method not implemented', __FUNCTION__);
3481 $row = $this->fetchRow($fetchmode, $rownum);
3485 if (!array_key_exists($colnum,
$row)) {
3487 'column is not defined in the result set: '.$colnum, __FUNCTION__);
3489 return $row[$colnum];
3508 $row = $this->fetchRow($fetchmode);
3509 if (is_array(
$row)) {
3510 if (!array_key_exists($colnum,
$row)) {
3512 'column is not defined in the result set: '.$colnum, __FUNCTION__);
3515 $column[] =
$row[$colnum];
3516 }
while (is_array(
$row = $this->fetchRow($fetchmode)));
3551 $force_array =
false, $group =
false)
3554 $row = $this->fetchRow($fetchmode);
3561 $shift_array = $rekey ? false : null;
3562 if (!is_null($shift_array)) {
3563 if (is_object(
$row)) {
3564 $colnum = count(get_object_vars(
$row));
3566 $colnum = count(
$row);
3570 'rekey feature requires atleast 2 column', __FUNCTION__);
3572 $shift_array = (!$force_array && $colnum == 2);
3577 if (is_object(
$row)) {
3578 $arr = get_object_vars(
$row);
3580 unset(
$row->{$key});
3586 $key = array_shift(
$row);
3593 $all[$key][] =
$row;
3597 }
while ((
$row = $this->fetchRow($fetchmode)));
3600 foreach (
$row as $key => $val) {
3601 $all[$key][] = $val;
3603 }
while ((
$row = $this->fetchRow($fetchmode)));
3607 }
while ((
$row = $this->fetchRow($fetchmode)));
3623 return $this->rownum + 1;
3639 'method not implemented', __FUNCTION__);
3655 'method not implemented', __FUNCTION__);
3676 if (!isset($this->column_names)) {
3677 $result = $this->_getColumnNames();
3681 $this->column_names =
$result;
3684 return array_flip($this->column_names);
3686 return $this->column_names;
3705 'method not implemented', __FUNCTION__);
3722 'method not implemented', __FUNCTION__);
3756 if (!is_numeric($column)) {
3757 $column_names = $this->getColumnNames();
3759 if ($this->db->options[
'field_case'] == CASE_LOWER) {
3760 $column = strtolower($column);
3762 $column = strtoupper($column);
3765 $column = $column_names[$column];
3767 $this->values[$column] =& $value;
3768 if (!is_null($type)) {
3769 $this->types[$column] = $type;
3789 foreach (
$row as $column => $value) {
3790 if (array_key_exists($column, $this->values)) {
3791 $this->values[$column] = $value;
3809 $this->result =
false;
3837 foreach (
$row as $key => $value) {
3838 $this->$key = &
$row[$key];
3852 $this->__construct(
$row);
3877 var $values = array();
3888 function __construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip =
false, $limit = null, $offset = null)
3891 $this->statement =& $statement;
3892 $this->positions = $positions;
3894 $this->types = (array)$types;
3895 $this->result_types = (array)$result_types;
3896 $this->limit = $limit;
3897 $this->is_manip = $is_manip;
3898 $this->offset = $offset;
3907 function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip =
false, $limit = null, $offset = null)
3909 $this->__construct($db, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
3930 if (!is_numeric($parameter)) {
3931 $parameter = preg_replace(
'/^:(.*)$/',
'\\1', $parameter);
3933 if (!in_array($parameter, $this->positions)) {
3935 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
3937 $this->values[$parameter] = $value;
3938 if (!is_null($type)) {
3939 $this->types[$parameter] = $type;
3962 $types = is_array($types) ? array_values($types) : array_fill(0, count($values), null);
3963 $parameters = array_keys($values);
3964 foreach ($parameters as $key => $parameter) {
3965 $err = $this->bindValue($parameter, $values[$parameter], $types[$key]);
3991 if (!is_numeric($parameter)) {
3992 $parameter = preg_replace(
'/^:(.*)$/',
'\\1', $parameter);
3994 if (!in_array($parameter, $this->positions)) {
3996 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
3998 $this->values[$parameter] =& $value;
3999 if (!is_null($type)) {
4000 $this->types[$parameter] = $type;
4023 $types = is_array($types) ? array_values($types) : array_fill(0, count($values), null);
4024 $parameters = array_keys($values);
4025 foreach ($parameters as $key => $parameter) {
4026 $err = $this->bindParam($parameter, $values[$parameter], $types[$key]);
4050 function &
execute($values = null, $result_class =
true, $result_wrap_class =
false)
4052 if (is_null($this->positions)) {
4053 return $this->db->raiseError(
MDB2_ERROR, null, null,
4054 'Prepared statement has already been freed', __FUNCTION__);
4057 $values = (array)$values;
4058 if (!empty($values)) {
4059 $err = $this->bindValueArray($values);
4061 return $this->db->raiseError(
MDB2_ERROR, null, null,
4062 'Binding Values failed with message: ' . $err->getMessage(), __FUNCTION__);
4065 $result =& $this->_execute($result_class, $result_wrap_class);
4082 function &
_execute($result_class =
true, $result_wrap_class =
false)
4087 foreach ($this->positions as $current_position => $parameter) {
4088 if (!array_key_exists($parameter, $this->values)) {
4090 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
4092 $value = $this->values[$parameter];
4093 $query.= substr($this->query, $last_position, $current_position - $last_position);
4094 if (!isset($value)) {
4095 $value_quoted =
'NULL';
4097 $type = !empty($this->types[$parameter]) ? $this->types[$parameter] : null;
4098 $value_quoted = $this->db->quote($value, $type);
4100 return $value_quoted;
4103 $query.= $value_quoted;
4104 $last_position = $current_position + 1;
4106 $query.= substr($this->query, $last_position);
4108 $this->db->offset = $this->offset;
4109 $this->db->limit = $this->limit;
4110 if ($this->is_manip) {
4111 $result = $this->db->exec($query);
4113 $result =& $this->db->query($query, $this->result_types, $result_class, $result_wrap_class);
4130 if (is_null($this->positions)) {
4131 return $this->db->raiseError(
MDB2_ERROR, null, null,
4132 'Prepared statement has already been freed', __FUNCTION__);
4135 $this->statement = null;
4136 $this->positions = null;
4137 $this->query = null;
4138 $this->types = null;
4139 $this->result_types = null;
4140 $this->limit = null;
4141 $this->is_manip = null;
4142 $this->offset = null;
4143 $this->values = null;
4182 $this->db_index = $db_index;
4193 $this->__construct($db_index);
4208 if (isset(
$GLOBALS[
'_MDB2_databases'][$this->db_index])) {
4212 'could not find MDB2 instance');
4233 reset(
$GLOBALS[
'_MDB2_databases']);
4234 while (next(
$GLOBALS[
'_MDB2_databases'])) {
4235 $key = key(
$GLOBALS[
'_MDB2_databases']);
4236 if (
$GLOBALS[
'_MDB2_databases'][$key]->opened_persistent
4237 &&
$GLOBALS[
'_MDB2_databases'][$key]->in_transaction
4239 $GLOBALS[
'_MDB2_databases'][$key]->rollback();
4265 $db->debug_output.= $scope.
'('.$db->db_index.
'): ';
4266 $db->debug_output.= $message.$db->getOption(
'log_line_break');
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
getOption($option)
Returns the value of an option.
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
nextID($seq_name, $ondemand=true)
Returns the next free id of a sequence.
bindColumn($column, &$value, $type=null)
Set bind variable to a column.
const MDB2_ERROR_CANNOT_REPLACE
getResource()
return the resource associated with the result object
MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip=false, $limit=null, $offset=null)
PHP 4 Constructor.
beginTransaction($savepoint=null)
Start a transaction or set a savepoint.
_affectedRows($connection, $result=null)
Returns the number of rows affected.
getIndexName($idx)
adds index name formatting to a index name
loadFile($file)
load a file (like 'Date')
MDB2_Driver_Common()
PHP 4 Constructor.
isResult($value)
Tell whether a value is a MDB2 result.
setTransactionIsolation($isolation, $options=array())
Set the transacton isolation level.
const MDB2_FETCHMODE_DEFAULT
This is a special constant that tells MDB2 the user hasn't specified any particular get mode...
isError($data, $code=null)
Tell whether a value is a MDB2 error.
const MDB2_ERROR_UNSUPPORTED
supports($feature)
Tell whether a DB implementation or its backend extension supports a given feature.
const MDB2_ERROR_NOSUCHDB
bindValue($parameter, $value, $type=null)
Set the value of a parameter of a prepared query.
while(false !==( $line=fgets( $in))) if(! $columns) $ignore
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
const MDB2_ERROR_CANNOT_DROP
$GLOBALS['_MDB2_databases']
These are global variables that are used to track the various class instances.
const MDB2_PORTABILITY_EMPTY_TO_NULL
Portability: convert empty values to null strings in data output by query*() and fetch*().
const MDB2_OK
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these...
const MDB2_ERROR_NOT_CAPABLE
const MDB2_ERROR_CANNOT_ALTER
const MDB2_ERROR_CANNOT_DELETE
__toString()
String conversation.
__construct(&$db, &$result, $limit=0, $offset=0)
Constructor.
bindValueArray($values, $types=null)
Set the values of multiple a parameter of a prepared query in bulk.
disconnect($force=true)
Log out and disconnect from the database.
const MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES
Portability: removes database/table qualifiers from associative indexes.
fetchAll($fetchmode=MDB2_FETCHMODE_DEFAULT, $rekey=false, $force_array=false, $group=false)
Fetch and return all rows from the current row pointer position.
free()
Free the internal references so that the instance can be destroyed.
bindParamArray(&$values, $types=null)
Bind the variables of multiple a parameter of a prepared query in bulk.
connect()
Connect to the database.
fetchCol($colnum=0)
Fetch and return a column from the current row pointer position.
& exec($query)
Execute a manipulation query to the database and return the number of affected rows.
apiVersion()
Return the MDB2 API version.
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.
numCols()
Count the number of columns returned by the DBMS in a query result.
quoteIdentifier($str, $check_option=false)
Quote a string so it can be safely used as a table or column name.
beginNestedTransaction()
Start a nested transaction.
setDatabase($name)
Select a different database.
numRows()
Returns the number of rows in a result object.
_assignBindColumns($row)
Bind a variable to a value in the result row.
compareDefinition($current, $previous)
Obtain an array of changes that may need to applied.
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
MDB2_Error($code=MDB2_ERROR, $mode=PEAR_ERROR_RETURN, $level=E_USER_NOTICE, $debuginfo=null)
MDB2_Error constructor.
rowCount()
Returns the actual row number that was last fetched (count from 0)
const MDB2_ERROR_CONSTRAINT
commit($savepoint=null)
Commit the database changes done during a transaction that is in progress or release a savepoint...
getSequenceName($sqn)
adds sequence name formatting to a sequence name
_getColumnNames()
Retrieve the names of columns returned by the DBMS in a query result.
free()
Release resources allocated for the specified prepared query.
getDebugOutput()
output debug info
const MDB2_ERROR_INVALID_DATE
MDB2_closeOpenTransactions()
Close any open transactions form persistent connections.
escape($text, $escape_wildcards=false)
Quotes a string so it can be safely used in a query.
& prepare($query, $types=null, $result_types=null, $lobs=array())
Prepares a query for multiple execution with execute().
_modifyQuery($query, $is_manip, $limit, $offset)
Changes a query string for various DBMS specific reasons.
const MDB2_ERROR_INVALID_DSN
const MDB2_ERROR_NOSUCHFIELD
& query($query, $types=null, $result_class=true, $result_wrap_class=false)
Send a query to the database and return any results.
const MDB2_FETCHMODE_OBJECT
Column data as object properties.
debug($message, $scope='', $context=array())
set a debug message
& _wrapResult($result, $types=array(), $result_class=true, $result_wrap_class=false, $limit=null, $offset=null)
wrap a result set into the correct class
_skipDelimitedStrings($query, $position, $p_position)
Utility method, used by prepare() to avoid replacing placeholders within delimited strings...
MDB2_Module_Common($db_index)
PHP 4 Constructor.
const MDB2_FETCHMODE_ORDERED
Column data indexed by numbers, ordered from 0 and up.
__construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip=false, $limit=null, $offset=null)
Constructor.
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
& standaloneQuery($query, $types=null, $is_manip=false)
execute a query as database administrator
if(!is_array($argv)) $options
failNestedTransaction($error=null, $immediately=false)
Force setting nested transaction to failed.
replace($table, $fields)
Execute a SQL REPLACE query.
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
& factory($dsn, $options=false)
Create a new MDB2 object for the specified database type.
const MDB2_ERROR_NEED_MORE_DATA
getNestedTransactionError()
The first error that occured since the transaction start.
const MDB2_PORTABILITY_RTRIM
Portability: right trim the data output by query*() and fetch*().
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
setOption($option, $value)
set the option for the db class
setResultTypes($types)
Define the list of types to be associated with the columns of a given result set. ...
isStatement($value)
Tell whether a value is a MDB2 statement interface.
const MDB2_PORTABILITY_ALL
Portability: turn on all portability features.
loadClass($class_name, $debug)
Loads a PEAR class.
const PEAR_ERROR_RETURN
#+ ERROR constants
const MDB2_ERROR_NOT_FOUND
completeNestedTransaction($force_rollback=false)
Finish a nested transaction by rolling back if an error occured or committing otherwise.
classExists($classname)
Checks if a class exists without triggering __autoload.
lastInsertID($table=null, $field=null)
Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $tab...
seek($rownum=0)
Seek to a specific row in a result set.
const MDB2_ERROR_NOT_LOCKED
& raiseError($code=null, $mode=null, $options=null, $userinfo=null, $method=null)
This method is used to communicate an error and invoke error callbacks etc.
const MDB2_ERROR_CONNECT_FAILED
& _execute($result_class=true, $result_wrap_class=false)
Execute a prepared query statement helper method.
inTransaction($ignore_nested=false)
If a transaction is currently open.
const MDB2_ERROR_CONSTRAINT_NOT_NULL
_fixResultArrayValues(&$row, $mode)
Do all necessary conversions on result arrays to fix DBMS quirks.
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...
currID($seq_name)
Returns the current id of a sequence.
const MDB2_ERROR_CANNOT_CREATE
getDatabase()
Get the current database.
isConnection($value)
Tell whether a value is a MDB2 connection.
const MDB2_ERROR_MISMATCH
& singleton($dsn=null, $options=false)
Returns a MDB2 connection with the requested DSN.
__call($method, $params)
Calls a module method using the __call magic method.
const MDB2_ERROR_VALUE_COUNT_ON_ROW
nextResult()
Move the internal result pointer to the next available result.
bindParam($parameter, &$value, $type=null)
Bind a variable to a parameter of a prepared query.
__construct(&$row)
constructor
fetchOne($colnum=0, $rownum=null)
fetch single column from the next row from a result set
escapePattern($text)
Quotes pattern (% and _) characters in a string)
& execute($values=null, $result_class=true, $result_wrap_class=false)
Execute a prepared query statement.
const MDB2_ERROR_INVALID_NUMBER
const MDB2_ERROR_EXTENSION_NOT_FOUND
getConnection()
Returns a native connection.
& raiseError($code=null, $mode=null, $options=null, $userinfo=null)
This method is used to communicate an error and invoke error callbacks etc.
& 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...
__construct($db_index)
Constructor.
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...
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 ...
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
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...
const MDB2_ERROR_NODBSELECTED
const MDB2_ERROR_DEADLOCK
const MDB2_ERROR_TRUNCATED
getDSN($type='string', $hidepw=false)
return the DSN as a string
setOptions(&$db, $options)
set option array in an exiting database object
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...
rollback($savepoint=null)
Cancel any database changes done during a transaction or since a specific savepoint that is in progre...
errorMessage($value=null)
Return a textual error message for a MDB2 error code.
MDB2_defaultDebugOutput(&$db, $scope, $message, $context=array())
default debug output handler
const MDB2_ERROR_LOADMODULE
fileExists($file)
Checks if a file exists in the include path.
const MDB2_ERROR_ACCESS_VIOLATION
setCharset($charset, $connection=null)
Set the charset on the current connection.
resetWarnings()
reset the warning array
MDB2_Row(&$row)
PHP 4 Constructor.
getServerVersion($native=false)
return version information about the server
errorInfo($error=null)
This method is used to collect information about an error.
getColumnNames($flip=false)
Retrieve the names of columns returned by the DBMS in a query result or from the cache.
free()
Free the internal resources associated with result.
& loadModule($module, $property=null, $phptype_specific=null)
loads a module
getDeclaration($type, $name, $field)
Obtain DBMS specific SQL code portion needed to declare of the given type.
const MDB2_ERROR_ALREADY_EXISTS
const MDB2_PORTABILITY_FIX_CASE
Portability: convert names of tables and fields to case defined in the "field_case" option when using...
__construct()
Constructor.
MDB2_Result_Common(&$db, &$result, $limit=0, $offset=0)
PHP 4 Constructor.
isError($data, $code=null)
Tell whether a value is a PEAR error.
getAsKeyword()
Gets the string to alias column.
subSelect($query, $type=false)
simple subselect emulation: leaves the query untouched for all RDBMS that support subselects ...
setFetchMode($fetchmode, $object_class='stdClass')
Sets which fetch mode should be used by default on queries on this connection.
getWarnings()
Get all warnings in reverse order.
const MDB2_ERROR_NOSUCHTABLE