Changeset 23022 for branches/version-2_13-dev/data/module/MDB2.php
- Timestamp:
- 2013/08/02 13:22:57 (13 years ago)
- File:
-
- 1 edited
-
branches/version-2_13-dev/data/module/MDB2.php (modified) (144 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/module/MDB2.php
r20764 r23022 44 44 // +----------------------------------------------------------------------+ 45 45 // 46 // $Id: MDB2.php ,v 1.335 2008/11/29 14:57:01 afz Exp$46 // $Id: MDB2.php 328183 2012-10-29 15:10:42Z danielc $ 47 47 // 48 48 … … 268 268 class MDB2 269 269 { 270 // {{{ function setOptions( &$db, $options)270 // {{{ function setOptions($db, $options) 271 271 272 272 /** … … 280 280 * @access public 281 281 */ 282 function setOptions(&$db, $options)282 static function setOptions($db, $options) 283 283 { 284 284 if (is_array($options)) { 285 285 foreach ($options as $option => $value) { 286 286 $test = $db->setOption($option, $value); 287 if ( PEAR::isError($test)) {287 if (MDB2::isError($test)) { 288 288 return $test; 289 289 } … … 305 305 * @access public 306 306 */ 307 function classExists($classname) 308 { 309 if (version_compare(phpversion(), "5.0", ">=")) { 310 return class_exists($classname, false); 311 } 312 return class_exists($classname); 307 static function classExists($classname) 308 { 309 return class_exists($classname, false); 313 310 } 314 311 … … 326 323 * @access public 327 324 */ 328 function loadClass($class_name, $debug)325 static function loadClass($class_name, $debug) 329 326 { 330 327 if (!MDB2::classExists($class_name)) { … … 341 338 $msg = "unable to load class '$class_name' from file '$file_name'"; 342 339 } 343 $err = &MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg);340 $err = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg); 344 341 return $err; 345 342 } 343 if (!MDB2::classExists($class_name)) { 344 $msg = "unable to load class '$class_name' from file '$file_name'"; 345 $err = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg); 346 return $err; 347 } 346 348 } 347 349 return MDB2_OK; … … 349 351 350 352 // }}} 351 // {{{ function &factory($dsn, $options = false)353 // {{{ function factory($dsn, $options = false) 352 354 353 355 /** 354 356 * Create a new MDB2 object for the specified database type 355 *356 * IMPORTANT: In order for MDB2 to work properly it is necessary that357 * you make sure that you work with a reference of the original358 * object instead of a copy (this is a PHP4 quirk).359 *360 * For example:361 * $db =& MDB2::factory($dsn);362 * ^^363 * And not:364 * $db = MDB2::factory($dsn);365 357 * 366 358 * @param mixed 'data source name', see the MDB2::parseDSN … … 375 367 * @access public 376 368 */ 377 function &factory($dsn, $options = false)369 static function factory($dsn, $options = false) 378 370 { 379 371 $dsninfo = MDB2::parseDSN($dsn); 380 372 if (empty($dsninfo['phptype'])) { 381 $err = &MDB2::raiseError(MDB2_ERROR_NOT_FOUND,373 $err = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, 382 374 null, null, 'no RDBMS driver specified'); 383 375 return $err; … … 387 379 $debug = (!empty($options['debug'])); 388 380 $err = MDB2::loadClass($class_name, $debug); 389 if ( PEAR::isError($err)) {381 if (MDB2::isError($err)) { 390 382 return $err; 391 383 } 392 384 393 $db = &new $class_name();385 $db = new $class_name(); 394 386 $db->setDSN($dsninfo); 395 387 $err = MDB2::setOptions($db, $options); 396 if ( PEAR::isError($err)) {388 if (MDB2::isError($err)) { 397 389 return $err; 398 390 } … … 402 394 403 395 // }}} 404 // {{{ function &connect($dsn, $options = false)396 // {{{ function connect($dsn, $options = false) 405 397 406 398 /** 407 399 * Create a new MDB2_Driver_* connection object and connect to the specified 408 400 * database 409 *410 * IMPORTANT: In order for MDB2 to work properly it is necessary that411 * you make sure that you work with a reference of the original412 * object instead of a copy (this is a PHP4 quirk).413 *414 * For example:415 * $db =& MDB2::connect($dsn);416 * ^^417 * And not:418 * $db = MDB2::connect($dsn);419 * ^^420 401 * 421 402 * @param mixed $dsn 'data source name', see the MDB2::parseDSN … … 432 413 * @see MDB2::parseDSN 433 414 */ 434 function &connect($dsn, $options = false)435 { 436 $db = &MDB2::factory($dsn, $options);437 if ( PEAR::isError($db)) {415 static function connect($dsn, $options = false) 416 { 417 $db = MDB2::factory($dsn, $options); 418 if (MDB2::isError($db)) { 438 419 return $db; 439 420 } 440 421 441 422 $err = $db->connect(); 442 if ( PEAR::isError($err)) {423 if (MDB2::isError($err)) { 443 424 $dsn = $db->getDSN('string', 'xxx'); 444 425 $db->disconnect(); … … 451 432 452 433 // }}} 453 // {{{ function &singleton($dsn = null, $options = false)434 // {{{ function singleton($dsn = null, $options = false) 454 435 455 436 /** … … 457 438 * A new MDB2 connection object is only created if no object with the 458 439 * requested DSN exists yet. 459 *460 * IMPORTANT: In order for MDB2 to work properly it is necessary that461 * you make sure that you work with a reference of the original462 * object instead of a copy (this is a PHP4 quirk).463 *464 * For example:465 * $db =& MDB2::singleton($dsn);466 * ^^467 * And not:468 * $db = MDB2::singleton($dsn);469 * ^^470 440 * 471 441 * @param mixed 'data source name', see the MDB2::parseDSN … … 482 452 * @see MDB2::parseDSN 483 453 */ 484 function &singleton($dsn = null, $options = false)454 static function singleton($dsn = null, $options = false) 485 455 { 486 456 if ($dsn) { … … 498 468 } 499 469 } elseif (is_array($GLOBALS['_MDB2_databases']) && reset($GLOBALS['_MDB2_databases'])) { 500 $db =& $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])]; 501 return $db; 502 } 503 $db =& MDB2::factory($dsn, $options); 470 return $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])]; 471 } 472 $db = MDB2::factory($dsn, $options); 504 473 return $db; 505 474 } … … 517 486 * @return boolean 518 487 */ 519 function areEquals($arr1, $arr2)488 static function areEquals($arr1, $arr2) 520 489 { 521 490 if (count($arr1) != count($arr2)) { … … 536 505 * load a file (like 'Date') 537 506 * 538 * @param stringname of the file in the MDB2 directory (without '.php')539 * 540 * @return stringname of the file that was included541 * 542 * @access public 543 */ 544 function loadFile($file)507 * @param string $file name of the file in the MDB2 directory (without '.php') 508 * 509 * @return string name of the file that was included 510 * 511 * @access public 512 */ 513 static function loadFile($file) 545 514 { 546 515 $file_name = 'MDB2'.DIRECTORY_SEPARATOR.$file.'.php'; … … 566 535 * @access public 567 536 */ 568 function apiVersion()569 { 570 return '2.5.0b 2';537 static function apiVersion() 538 { 539 return '2.5.0b5'; 571 540 } 572 541 … … 598 567 * @see PEAR_Error 599 568 */ 600 function &raiseError($code = null,569 public static function &raiseError($code = null, 601 570 $mode = null, 602 571 $options = null, … … 606 575 $dummy3 = false) 607 576 { 608 $err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true); 577 $pear = new PEAR; 578 $err =& $pear->raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true); 609 579 return $err; 610 580 } … … 626 596 * @access public 627 597 */ 628 function isError($data, $code = null)629 { 630 if ( is_a($data, 'MDB2_Error')) {631 if ( is_null($code)) {598 static function isError($data, $code = null) 599 { 600 if ($data instanceof MDB2_Error) { 601 if (null === $code) { 632 602 return true; 633 } elseif (is_string($code)) { 603 } 604 if (is_string($code)) { 634 605 return $data->getMessage() === $code; 635 } else { 636 $code = (array)$code; 637 return in_array($data->getCode(), $code); 638 } 606 } 607 return in_array($data->getCode(), (array)$code); 639 608 } 640 609 return false; … … 650 619 * 651 620 * @return bool whether $value is a MDB2 connection 652 * 653 * @access public 654 */ 655 function isConnection($value) 656 { 657 return is_a($value, 'MDB2_Driver_Common'); 621 * @access public 622 */ 623 static function isConnection($value) 624 { 625 return ($value instanceof MDB2_Driver_Common); 658 626 } 659 627 … … 664 632 * Tell whether a value is a MDB2 result 665 633 * 634 * @param mixed $value value to test 635 * 636 * @return bool whether $value is a MDB2 result 637 * 638 * @access public 639 */ 640 static function isResult($value) 641 { 642 return ($value instanceof MDB2_Result); 643 } 644 645 // }}} 646 // {{{ function isResultCommon($value) 647 648 /** 649 * Tell whether a value is a MDB2 result implementing the common interface 650 * 651 * @param mixed $value value to test 652 * 653 * @return bool whether $value is a MDB2 result implementing the common interface 654 * 655 * @access public 656 */ 657 static function isResultCommon($value) 658 { 659 return ($value instanceof MDB2_Result_Common); 660 } 661 662 // }}} 663 // {{{ function isStatement($value) 664 665 /** 666 * Tell whether a value is a MDB2 statement interface 667 * 666 668 * @param mixed value to test 667 669 * 668 * @return bool whether $value is a MDB2 result669 *670 * @access public671 */672 function isResult($value)673 {674 return is_a($value, 'MDB2_Result');675 }676 677 // }}}678 // {{{ function isResultCommon($value)679 680 /**681 * Tell whether a value is a MDB2 result implementing the common interface682 *683 * @param mixed value to test684 *685 * @return bool whether $value is a MDB2 result implementing the common interface686 *687 * @access public688 */689 function isResultCommon($value)690 {691 return is_a($value, 'MDB2_Result_Common');692 }693 694 // }}}695 // {{{ function isStatement($value)696 697 /**698 * Tell whether a value is a MDB2 statement interface699 *700 * @param mixed value to test701 *702 670 * @return bool whether $value is a MDB2 statement interface 703 671 * 704 672 * @access public 705 673 */ 706 function isStatement($value)707 { 708 return is_a($value, 'MDB2_Statement_Common');674 static function isStatement($value) 675 { 676 return ($value instanceof MDB2_Statement_Common); 709 677 } 710 678 … … 724 692 * @access public 725 693 */ 726 function errorMessage($value = null)694 static function errorMessage($value = null) 727 695 { 728 696 static $errorMessages; … … 773 741 } 774 742 775 if ( is_null($value)) {743 if (null === $value) { 776 744 return $errorMessages; 777 745 } 778 746 779 if ( PEAR::isError($value)) {747 if (MDB2::isError($value)) { 780 748 $value = $value->getCode(); 781 749 } … … 825 793 * @author Tomas V.V.Cox <[email protected]> 826 794 */ 827 function parseDSN($dsn)795 static function parseDSN($dsn) 828 796 { 829 797 $parsed = $GLOBALS['_MDB2_dsninfo_default']; … … 894 862 //e.g. "scott/tiger@//mymachine:1521/oracle" 895 863 $proto_opts = $dsn; 896 $dsn = substr($proto_opts, strrpos($proto_opts, '/') + 1); 864 $pos = strrpos($proto_opts, '/'); 865 $dsn = substr($proto_opts, $pos + 1); 866 $proto_opts = substr($proto_opts, 0, $pos); 897 867 } elseif (strpos($dsn, '/') !== false) { 898 868 list($proto_opts, $dsn) = explode('/', $dsn, 2); … … 920 890 // /database 921 891 if (($pos = strpos($dsn, '?')) === false) { 922 $parsed['database'] = $dsn;892 $parsed['database'] = rawurldecode($dsn); 923 893 // /database?param1=value1¶m2=value2 924 894 } else { 925 $parsed['database'] = substr($dsn, 0, $pos);895 $parsed['database'] = rawurldecode(substr($dsn, 0, $pos)); 926 896 $dsn = substr($dsn, $pos + 1); 927 897 if (strpos($dsn, '&') !== false) { … … 932 902 foreach ($opts as $opt) { 933 903 list($key, $value) = explode('=', $opt); 934 if (! isset($parsed[$key])) {904 if (!array_key_exists($key, $parsed) || false === $parsed[$key]) { 935 905 // don't allow params overwrite 936 906 $parsed[$key] = rawurldecode($value); … … 955 925 * @access public 956 926 */ 957 function fileExists($file)927 static function fileExists($file) 958 928 { 959 929 // safe_mode does notwork with is_readable() … … 1000 970 * @param mixed additional debug info, such as the last query 1001 971 */ 1002 function MDB2_Error($code = MDB2_ERROR, $mode = PEAR_ERROR_RETURN,972 function __construct($code = MDB2_ERROR, $mode = PEAR_ERROR_RETURN, 1003 973 $level = E_USER_NOTICE, $debuginfo = null, $dummy = null) 1004 974 { 1005 if ( is_null($code)) {975 if (null === $code) { 1006 976 $code = MDB2_ERROR; 1007 977 } … … 1023 993 * @author Lukas Smith <[email protected]> 1024 994 */ 1025 class MDB2_Driver_Common extends PEAR995 class MDB2_Driver_Common 1026 996 { 1027 997 // {{{ Variables (Properties) 1028 998 1029 999 /** 1000 * @var MDB2_Driver_Datatype_Common 1001 */ 1002 public $datatype; 1003 1004 /** 1005 * @var MDB2_Extended 1006 */ 1007 public $extended; 1008 1009 /** 1010 * @var MDB2_Driver_Function_Common 1011 */ 1012 public $function; 1013 1014 /** 1015 * @var MDB2_Driver_Manager_Common 1016 */ 1017 public $manager; 1018 1019 /** 1020 * @var MDB2_Driver_Native_Commonn 1021 */ 1022 public $native; 1023 1024 /** 1025 * @var MDB2_Driver_Reverse_Common 1026 */ 1027 public $reverse; 1028 1029 /** 1030 1030 * index of the MDB2 object within the $GLOBALS['_MDB2_databases'] array 1031 1031 * @var int 1032 1032 * @access public 1033 1033 */ 1034 var$db_index = 0;1034 public $db_index = 0; 1035 1035 1036 1036 /** … … 1039 1039 * @access protected 1040 1040 */ 1041 var$dsn = array();1041 public $dsn = array(); 1042 1042 1043 1043 /** … … 1046 1046 * @access protected 1047 1047 */ 1048 var$connected_dsn = array();1048 public $connected_dsn = array(); 1049 1049 1050 1050 /** … … 1053 1053 * @access protected 1054 1054 */ 1055 var$connection = 0;1055 public $connection = 0; 1056 1056 1057 1057 /** … … 1060 1060 * @access protected 1061 1061 */ 1062 var$opened_persistent;1062 public $opened_persistent; 1063 1063 1064 1064 /** 1065 1065 * the name of the database for the next query 1066 1066 * @var string 1067 * @access p rotected1068 */ 1069 var$database_name = '';1067 * @access public 1068 */ 1069 public $database_name = ''; 1070 1070 1071 1071 /** … … 1074 1074 * @access protected 1075 1075 */ 1076 var$connected_database_name = '';1076 public $connected_database_name = ''; 1077 1077 1078 1078 /** … … 1081 1081 * @access protected 1082 1082 */ 1083 var$connected_server_info = '';1083 public $connected_server_info = ''; 1084 1084 1085 1085 /** … … 1088 1088 * @access public 1089 1089 */ 1090 var$supported = array(1090 public $supported = array( 1091 1091 'sequences' => false, 1092 1092 'indexes' => false, … … 1113 1113 /** 1114 1114 * Array of supported options that can be passed to the MDB2 instance. 1115 * 1115 * 1116 1116 * The options can be set during object creation, using 1117 * MDB2::connect(), MDB2::factory() or MDB2::singleton(). The options can 1118 * also be set after the object is created, using MDB2::setOptions() or 1117 * MDB2::connect(), MDB2::factory() or MDB2::singleton(). The options can 1118 * also be set after the object is created, using MDB2::setOptions() or 1119 1119 * MDB2_Driver_Common::setOption(). 1120 1120 * The list of available option includes: … … 1162 1162 * @see MDB2_Driver_Common::setOption() 1163 1163 */ 1164 var$options = array(1164 public $options = array( 1165 1165 'ssl' => false, 1166 1166 'field_case' => CASE_LOWER, … … 1209 1209 * string array 1210 1210 * @var string 1211 * @access protected 1212 */ 1213 var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => false, 'escape_pattern' => false); 1211 * @access public 1212 */ 1213 public $string_quoting = array( 1214 'start' => "'", 1215 'end' => "'", 1216 'escape' => false, 1217 'escape_pattern' => false, 1218 ); 1214 1219 1215 1220 /** 1216 1221 * identifier quoting 1217 1222 * @var array 1218 * @access protected 1219 */ 1220 var $identifier_quoting = array('start' => '"', 'end' => '"', 'escape' => '"'); 1223 * @access public 1224 */ 1225 public $identifier_quoting = array( 1226 'start' => '"', 1227 'end' => '"', 1228 'escape' => '"', 1229 ); 1221 1230 1222 1231 /** … … 1225 1234 * @access protected 1226 1235 */ 1227 var$sql_comments = array(1236 public $sql_comments = array( 1228 1237 array('start' => '--', 'end' => "\n", 'escape' => false), 1229 1238 array('start' => '/*', 'end' => '*/', 'escape' => false), … … 1235 1244 * @access protected 1236 1245 */ 1237 var$wildcards = array('%', '_');1246 protected $wildcards = array('%', '_'); 1238 1247 1239 1248 /** … … 1242 1251 * @access protected 1243 1252 */ 1244 var$as_keyword = ' AS ';1253 public $as_keyword = ' AS '; 1245 1254 1246 1255 /** … … 1249 1258 * @access protected 1250 1259 */ 1251 var$warnings = array();1260 public $warnings = array(); 1252 1261 1253 1262 /** … … 1256 1265 * @access public 1257 1266 */ 1258 var$debug_output = '';1267 public $debug_output = ''; 1259 1268 1260 1269 /** … … 1263 1272 * @access protected 1264 1273 */ 1265 var$in_transaction = false;1274 public $in_transaction = false; 1266 1275 1267 1276 /** … … 1270 1279 * @access protected 1271 1280 */ 1272 var$nested_transaction_counter = null;1281 public $nested_transaction_counter = null; 1273 1282 1274 1283 /** … … 1277 1286 * @access protected 1278 1287 */ 1279 var$has_transaction_error = false;1288 protected $has_transaction_error = false; 1280 1289 1281 1290 /** 1282 1291 * result offset used in the next query 1283 1292 * @var int 1284 * @access p rotected1285 */ 1286 var$offset = 0;1293 * @access public 1294 */ 1295 public $offset = 0; 1287 1296 1288 1297 /** 1289 1298 * result limit used in the next query 1290 1299 * @var int 1291 * @access p rotected1292 */ 1293 var$limit = 0;1300 * @access public 1301 */ 1302 public $limit = 0; 1294 1303 1295 1304 /** … … 1298 1307 * @access public 1299 1308 */ 1300 var$phptype;1309 public $phptype; 1301 1310 1302 1311 /** … … 1305 1314 * @access public 1306 1315 */ 1307 var$dbsyntax;1316 public $dbsyntax; 1308 1317 1309 1318 /** … … 1312 1321 * @access public 1313 1322 */ 1314 var$last_query;1323 public $last_query; 1315 1324 1316 1325 /** 1317 1326 * the default fetchmode used 1318 1327 * @var int 1319 * @access p rotected1320 */ 1321 var$fetchmode = MDB2_FETCHMODE_ORDERED;1328 * @access public 1329 */ 1330 public $fetchmode = MDB2_FETCHMODE_ORDERED; 1322 1331 1323 1332 /** … … 1326 1335 * @access protected 1327 1336 */ 1328 var$modules = array();1337 protected $modules = array(); 1329 1338 1330 1339 /** … … 1333 1342 * @access protected 1334 1343 */ 1335 var $destructor_registered = true; 1344 protected $destructor_registered = true; 1345 1346 /** 1347 * @var PEAR 1348 */ 1349 protected $pear; 1336 1350 1337 1351 // }}} … … 1347 1361 $GLOBALS['_MDB2_databases'][$db_index] = &$this; 1348 1362 $this->db_index = $db_index; 1349 } 1350 1351 // }}} 1352 // {{{ function MDB2_Driver_Common() 1353 1354 /** 1355 * PHP 4 Constructor 1356 */ 1357 function MDB2_Driver_Common() 1358 { 1359 $this->destructor_registered = false; 1360 $this->__construct(); 1363 $this->pear = new PEAR; 1361 1364 } 1362 1365 … … 1434 1437 * without the message string. 1435 1438 * 1436 * @param mixed $code integer error code, or a PEAR error object (all 1439 * @param mixed $code integer error code, or a PEAR error object (all 1437 1440 * other parameters are ignored if this parameter is 1438 1441 * an object … … 1464 1467 $userinfo = "[Error message: $userinfo]\n"; 1465 1468 // The error is yet a MDB2 error object 1466 if ( PEAR::isError($code)) {1469 if (MDB2::isError($code)) { 1467 1470 // because we use the static PEAR::raiseError, our global 1468 1471 // handler should be used if it is set 1469 if ( is_null($mode) && !empty($this->_default_error_mode)) {1472 if ((null === $mode) && !empty($this->_default_error_mode)) { 1470 1473 $mode = $this->_default_error_mode; 1471 1474 $options = $this->_default_error_options; 1472 1475 } 1473 if ( is_null($userinfo)) {1476 if (null === $userinfo) { 1474 1477 $userinfo = $code->getUserinfo(); 1475 1478 } … … 1484 1487 $native_errno = $native_msg = null; 1485 1488 list($code, $native_errno, $native_msg) = $this->errorInfo($code); 1486 if ( !is_null($native_errno) && $native_errno !== '') {1489 if ((null !== $native_errno) && $native_errno !== '') { 1487 1490 $userinfo.= "[Native code: $native_errno]\n"; 1488 1491 } 1489 if ( !is_null($native_msg) && $native_msg !== '') {1492 if ((null !== $native_msg) && $native_msg !== '') { 1490 1493 $userinfo.= "[Native message: ". strip_tags($native_msg) ."]\n"; 1491 1494 } 1492 if ( !is_null($method)) {1495 if (null !== $method) { 1493 1496 $userinfo = $method.': '.$userinfo; 1494 1497 } 1495 1498 } 1496 1499 1497 $err = & PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);1500 $err = $this->pear->raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true); 1498 1501 if ($err->getMode() !== PEAR_ERROR_RETURN 1499 1502 && isset($this->nested_transaction_counter) && !$this->has_transaction_error) { 1500 $this->has_transaction_error = &$err;1503 $this->has_transaction_error = $err; 1501 1504 } 1502 1505 return $err; … … 1791 1794 { 1792 1795 $result = $this->connect(); 1793 if ( PEAR::isError($result)) {1796 if (MDB2::isError($result)) { 1794 1797 return $result; 1795 1798 } … … 1879 1882 1880 1883 // }}} 1881 // {{{ function &loadModule($module, $property = null, $phptype_specific = null)1884 // {{{ function loadModule($module, $property = null, $phptype_specific = null) 1882 1885 1883 1886 /** … … 1895 1898 * @access public 1896 1899 */ 1897 function &loadModule($module, $property = null, $phptype_specific = null)1900 function loadModule($module, $property = null, $phptype_specific = null) 1898 1901 { 1899 1902 if (!$property) { … … 1917 1920 1918 1921 $err = MDB2::loadClass($class_name, $this->getOption('debug')); 1919 if ( PEAR::isError($err)) {1922 if (MDB2::isError($err)) { 1920 1923 return $err; 1921 1924 } … … 1928 1931 $class_name = $class_name_new; 1929 1932 $err = MDB2::loadClass($class_name, $this->getOption('debug')); 1930 if ( PEAR::isError($err)) {1933 if (MDB2::isError($err)) { 1931 1934 return $err; 1932 1935 } … … 1936 1939 1937 1940 if (!MDB2::classExists($class_name)) { 1938 $err = &$this->raiseError(MDB2_ERROR_LOADMODULE, null, null,1941 $err = $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, 1939 1942 "unable to load module '$module' into property '$property'", __FUNCTION__); 1940 1943 return $err; 1941 1944 } 1942 1945 $this->{$property} = new $class_name($this->db_index); 1943 $this->modules[$module] = &$this->{$property};1946 $this->modules[$module] = $this->{$property}; 1944 1947 if ($version) { 1945 1948 // this will be used in the connect method to determine if the module … … 1973 1976 $method = strtolower($match[2]).$match[3]; 1974 1977 if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) { 1975 $result = &$this->loadModule($module);1976 if ( PEAR::isError($result)) {1978 $result = $this->loadModule($module); 1979 if (MDB2::isError($result)) { 1977 1980 return $result; 1978 1981 } … … 1988 1991 } 1989 1992 } 1990 if ( !is_null($module)) {1993 if (null !== $module) { 1991 1994 return call_user_func_array(array(&$this->modules[$module], $method), $params); 1992 1995 } 1993 trigger_error(sprintf('Call to undefined function: %s::%s().', get_class($this), $method), E_USER_ERROR); 1996 1997 $class = get_class($this); 1998 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); 1999 $loc = 'in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line']; 2000 if ($method == 'isError') { 2001 trigger_error("Deprecated: $class::isError() is deprecated, use MDB2::isError() $loc", E_USER_DEPRECATED); 2002 if (!array_key_exists(0, $params)) { 2003 trigger_error("Missing argument 1 for $class::$method, called $loc", E_USER_ERROR); 2004 } 2005 return MDB2::isError($params[0]); 2006 } 2007 trigger_error("Call to undefined function: $class::$method() $loc.", E_USER_ERROR); 2008 } 2009 2010 // }}} 2011 // {{{ function __callStatic($method, $params) 2012 2013 /** 2014 * Calls a module method using the __callStatic magic method 2015 * 2016 * @param string Method name. 2017 * @param array Arguments. 2018 * 2019 * @return mixed Returned value. 2020 */ 2021 public static function __callStatic($method, $params) 2022 { 2023 $class = get_called_class(); 2024 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); 2025 $loc = 'in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line']; 2026 if ($method == 'isError') { 2027 trigger_error("Deprecated: $class::isError() is deprecated, use MDB2::isError() $loc", E_USER_DEPRECATED); 2028 if (!array_key_exists(0, $params)) { 2029 trigger_error("Missing argument 1 for $class::$method, called $loc", E_USER_ERROR); 2030 } 2031 return MDB2::isError($params[0]); 2032 } 2033 trigger_error("Call to undefined function: $class::$method() $loc.", E_USER_ERROR); 1994 2034 } 1995 2035 … … 2151 2191 if ($force_rollback || $this->has_transaction_error) { 2152 2192 $result = $this->rollback($savepoint); 2153 if (! PEAR::isError($result)) {2193 if (!MDB2::isError($result)) { 2154 2194 $result = false; 2155 2195 $this->has_transaction_error = false; … … 2172 2212 if ($force_rollback || $this->has_transaction_error) { 2173 2213 $result = $this->rollback(); 2174 if (! PEAR::isError($result)) {2214 if (!MDB2::isError($result)) { 2175 2215 $result = false; 2176 2216 } … … 2198 2238 function failNestedTransaction($error = null, $immediately = false) 2199 2239 { 2200 if ( is_null($error)) {2240 if (null !== $error) { 2201 2241 $error = $this->has_transaction_error ? $this->has_transaction_error : true; 2202 2242 } elseif (!$error) { … … 2433 2473 * @access public 2434 2474 */ 2435 function &standaloneQuery($query, $types = null, $is_manip = false)2475 function standaloneQuery($query, $types = null, $is_manip = false) 2436 2476 { 2437 2477 $offset = $this->offset; … … 2441 2481 2442 2482 $connection = $this->getConnection(); 2443 if ( PEAR::isError($connection)) {2483 if (MDB2::isError($connection)) { 2444 2484 return $connection; 2445 2485 } 2446 2486 2447 $result = &$this->_doQuery($query, $is_manip, $connection, false);2448 if ( PEAR::isError($result)) {2487 $result = $this->_doQuery($query, $is_manip, $connection, false); 2488 if (MDB2::isError($result)) { 2449 2489 return $result; 2450 2490 } … … 2454 2494 return $affected_rows; 2455 2495 } 2456 $result = & $this->_wrapResult($result, $types, true, false, $limit, $offset);2496 $result = $this->_wrapResult($result, $types, true, true, $limit, $offset); 2457 2497 return $result; 2458 2498 } … … 2492 2532 * @access protected 2493 2533 */ 2494 function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)2534 function _doQuery($query, $is_manip = false, $connection = null, $database_name = null) 2495 2535 { 2496 2536 $this->last_query = $query; 2497 2537 $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre')); 2498 2538 if ($result) { 2499 if ( PEAR::isError($result)) {2539 if (MDB2::isError($result)) { 2500 2540 return $result; 2501 2541 } 2502 2542 $query = $result; 2503 2543 } 2504 $err = & $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,2544 $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 2505 2545 'method not implemented', __FUNCTION__); 2506 2546 return $err; … … 2522 2562 function _affectedRows($connection, $result = null) 2523 2563 { 2524 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,2564 return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 2525 2565 'method not implemented', __FUNCTION__); 2526 2566 } … … 2538 2578 * @access public 2539 2579 */ 2540 function &exec($query)2580 function exec($query) 2541 2581 { 2542 2582 $offset = $this->offset; … … 2546 2586 2547 2587 $connection = $this->getConnection(); 2548 if ( PEAR::isError($connection)) {2588 if (MDB2::isError($connection)) { 2549 2589 return $connection; 2550 2590 } 2551 2591 2552 $result = &$this->_doQuery($query, true, $connection, $this->database_name);2553 if ( PEAR::isError($result)) {2592 $result = $this->_doQuery($query, true, $connection, $this->database_name); 2593 if (MDB2::isError($result)) { 2554 2594 return $result; 2555 2595 } … … 2575 2615 * @access public 2576 2616 */ 2577 function &query($query, $types = null, $result_class = true, $result_wrap_class = false)2617 function query($query, $types = null, $result_class = true, $result_wrap_class = true) 2578 2618 { 2579 2619 $offset = $this->offset; … … 2583 2623 2584 2624 $connection = $this->getConnection(); 2585 if ( PEAR::isError($connection)) {2625 if (MDB2::isError($connection)) { 2586 2626 return $connection; 2587 2627 } 2588 2628 2589 $result = &$this->_doQuery($query, false, $connection, $this->database_name);2590 if ( PEAR::isError($result)) {2629 $result = $this->_doQuery($query, false, $connection, $this->database_name); 2630 if (MDB2::isError($result)) { 2591 2631 return $result; 2592 2632 } 2593 2633 2594 $result = &$this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset);2634 $result = $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset); 2595 2635 return $result; 2596 2636 } 2597 2637 2598 2638 // }}} 2599 // {{{ function &_wrapResult($result, $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null)2639 // {{{ function _wrapResult($result_resource, $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null) 2600 2640 2601 2641 /** … … 2614 2654 * @access protected 2615 2655 */ 2616 function &_wrapResult($result, $types = array(), $result_class = true,2617 $result_wrap_class = false, $limit = null, $offset = null)2656 function _wrapResult($result_resource, $types = array(), $result_class = true, 2657 $result_wrap_class = true, $limit = null, $offset = null) 2618 2658 { 2619 2659 if ($types === true) { 2620 2660 if ($this->supports('result_introspection')) { 2621 2661 $this->loadModule('Reverse', null, true); 2622 $tableInfo = $this->reverse->tableInfo($result );2623 if ( PEAR::isError($tableInfo)) {2662 $tableInfo = $this->reverse->tableInfo($result_resource); 2663 if (MDB2::isError($tableInfo)) { 2624 2664 return $tableInfo; 2625 2665 } 2626 2666 $types = array(); 2667 $types_assoc = array(); 2627 2668 foreach ($tableInfo as $field) { 2628 2669 $types[] = $field['mdb2type']; 2670 $types_assoc[$field['name']] = $field['mdb2type']; 2629 2671 } 2630 2672 } else { … … 2641 2683 $class_name = sprintf($result_class, $this->phptype); 2642 2684 if (!MDB2::classExists($class_name)) { 2643 $err = & $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,2685 $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 2644 2686 'result class does not exist '.$class_name, __FUNCTION__); 2645 2687 return $err; 2646 2688 } 2647 $result = & new $class_name($this, $result, $limit, $offset);2689 $result = new $class_name($this, $result_resource, $limit, $offset); 2648 2690 if (!MDB2::isResultCommon($result)) { 2649 $err = & $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,2691 $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 2650 2692 'result class is not extended from MDB2_Result_Common', __FUNCTION__); 2651 2693 return $err; 2652 2694 } 2695 2653 2696 if (!empty($types)) { 2654 2697 $err = $result->setResultTypes($types); 2655 if ( PEAR::isError($err)) {2698 if (MDB2::isError($err)) { 2656 2699 $result->free(); 2657 2700 return $err; 2658 2701 } 2659 2702 } 2660 } 2661 if ($result_wrap_class === true) { 2662 $result_wrap_class = $this->options['result_wrap_class']; 2663 } 2664 if ($result_wrap_class) { 2665 if (!MDB2::classExists($result_wrap_class)) { 2666 $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 2667 'result wrap class does not exist '.$result_wrap_class, __FUNCTION__); 2668 return $err; 2669 } 2670 $result = new $result_wrap_class($result, $this->fetchmode); 2671 } 2672 return $result; 2703 if (!empty($types_assoc)) { 2704 $err = $result->setResultTypes($types_assoc); 2705 if (MDB2::isError($err)) { 2706 $result->free(); 2707 return $err; 2708 } 2709 } 2710 2711 if ($result_wrap_class === true) { 2712 $result_wrap_class = $this->options['result_wrap_class']; 2713 } 2714 if ($result_wrap_class) { 2715 if (!MDB2::classExists($result_wrap_class)) { 2716 $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 2717 'result wrap class does not exist '.$result_wrap_class, __FUNCTION__); 2718 return $err; 2719 } 2720 $result = new $result_wrap_class($result, $this->fetchmode); 2721 } 2722 2723 return $result; 2724 } 2725 2726 return $result_resource; 2673 2727 } 2674 2728 … … 2687 2741 function getServerVersion($native = false) 2688 2742 { 2689 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,2743 return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 2690 2744 'method not implemented', __FUNCTION__); 2691 2745 } … … 2707 2761 { 2708 2762 if (!$this->supports('limit_queries')) { 2709 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,2763 return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 2710 2764 'limit is not supported by this driver', __FUNCTION__); 2711 2765 } 2712 2766 $limit = (int)$limit; 2713 2767 if ($limit < 0) { 2714 return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,2768 return MDB2_Driver_Common::raiseError(MDB2_ERROR_SYNTAX, null, null, 2715 2769 'it was not specified a valid selected range row limit', __FUNCTION__); 2716 2770 } 2717 2771 $this->limit = $limit; 2718 if ( !is_null($offset)) {2772 if (null !== $offset) { 2719 2773 $offset = (int)$offset; 2720 2774 if ($offset < 0) { 2721 return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,2775 return MDB2_Driver_Common::raiseError(MDB2_ERROR_SYNTAX, null, null, 2722 2776 'it was not specified a valid first selected range row', __FUNCTION__); 2723 2777 } … … 2749 2803 2750 2804 if (!$this->supports('sub_selects')) { 2751 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,2805 return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 2752 2806 'method not implemented', __FUNCTION__); 2753 2807 } 2754 2808 2755 2809 $col = $this->queryCol($query, $type); 2756 if ( PEAR::isError($col)) {2810 if (MDB2::isError($col)) { 2757 2811 return $col; 2758 2812 } … … 2835 2889 { 2836 2890 if (!$this->supports('replace')) { 2837 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,2891 return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 2838 2892 'replace query is not supported', __FUNCTION__); 2839 2893 } … … 2851 2905 if (isset($fields[$name]['key']) && $fields[$name]['key']) { 2852 2906 if ($value === 'NULL') { 2853 return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,2907 return MDB2_Driver_Common::raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null, 2854 2908 'key value '.$name.' may not be NULL', __FUNCTION__); 2855 2909 } … … 2858 2912 } 2859 2913 if (empty($condition)) { 2860 return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,2914 return MDB2_Driver_Common::raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null, 2861 2915 'not specified which fields are keys', __FUNCTION__); 2862 2916 } … … 2864 2918 $result = null; 2865 2919 $in_transaction = $this->in_transaction; 2866 if (!$in_transaction && PEAR::isError($result = $this->beginTransaction())) {2920 if (!$in_transaction && MDB2::isError($result = $this->beginTransaction())) { 2867 2921 return $result; 2868 2922 } 2869 2923 2870 2924 $connection = $this->getConnection(); 2871 if ( PEAR::isError($connection)) {2925 if (MDB2::isError($connection)) { 2872 2926 return $connection; 2873 2927 } … … 2875 2929 $condition = ' WHERE '.implode(' AND ', $condition); 2876 2930 $query = 'DELETE FROM ' . $this->quoteIdentifier($table, true) . $condition; 2877 $result = &$this->_doQuery($query, true, $connection);2878 if (! PEAR::isError($result)) {2931 $result = $this->_doQuery($query, true, $connection); 2932 if (!MDB2::isError($result)) { 2879 2933 $affected_rows = $this->_affectedRows($connection, $result); 2880 2934 $insert = ''; … … 2884 2938 $values = implode(', ', $values); 2885 2939 $query = 'INSERT INTO '. $this->quoteIdentifier($table, true) . "($insert) VALUES ($values)"; 2886 $result = &$this->_doQuery($query, true, $connection);2887 if (! PEAR::isError($result)) {2940 $result = $this->_doQuery($query, true, $connection); 2941 if (!MDB2::isError($result)) { 2888 2942 $affected_rows += $this->_affectedRows($connection, $result);; 2889 2943 } … … 2891 2945 2892 2946 if (!$in_transaction) { 2893 if ( PEAR::isError($result)) {2947 if (MDB2::isError($result)) { 2894 2948 $this->rollback(); 2895 2949 } else { … … 2898 2952 } 2899 2953 2900 if ( PEAR::isError($result)) {2954 if (MDB2::isError($result)) { 2901 2955 return $result; 2902 2956 } … … 2925 2979 * @param mixed key (field) value (parameter) pair for all lob placeholders 2926 2980 * 2927 * @return mixed resource handle for the prepared query on success, 2981 * @return mixed resource handle for the prepared query on success, 2928 2982 * a MDB2 error on failure 2929 2983 * … … 2931 2985 * @see bindParam, execute 2932 2986 */ 2933 function &prepare($query, $types = null, $result_types = null, $lobs = array())2987 function prepare($query, $types = null, $result_types = null, $lobs = array()) 2934 2988 { 2935 2989 $is_manip = ($result_types === MDB2_PREPARE_MANIP); … … 2939 2993 $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre')); 2940 2994 if ($result) { 2941 if ( PEAR::isError($result)) {2995 if (MDB2::isError($result)) { 2942 2996 return $result; 2943 2997 } … … 2961 3015 break; 2962 3016 } 2963 if ( is_null($placeholder_type)) {3017 if (null === $placeholder_type) { 2964 3018 $placeholder_type_guess = $query[$p_position]; 2965 3019 } 2966 3020 2967 3021 $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position); 2968 if ( PEAR::isError($new_pos)) {3022 if (MDB2::isError($new_pos)) { 2969 3023 return $new_pos; 2970 3024 } … … 2975 3029 2976 3030 if ($query[$position] == $placeholder_type_guess) { 2977 if ( is_null($placeholder_type)) {3031 if (null === $placeholder_type) { 2978 3032 $placeholder_type = $query[$p_position]; 2979 3033 $question = $colon = $placeholder_type; … … 2994 3048 $parameter = preg_replace($regexp, '\\1', $query); 2995 3049 if ($parameter === '') { 2996 $err = & $this->raiseError(MDB2_ERROR_SYNTAX, null, null,3050 $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_SYNTAX, null, null, 2997 3051 'named parameter name must match "bindname_format" option', __FUNCTION__); 2998 3052 return $err; … … 3021 3075 // }}} 3022 3076 // {{{ function _skipDelimitedStrings($query, $position, $p_position) 3023 3077 3024 3078 /** 3025 3079 * Utility method, used by prepare() to avoid replacing placeholders within delimited strings. … … 3039 3093 function _skipDelimitedStrings($query, $position, $p_position) 3040 3094 { 3041 $ignores = $this->string_quoting; 3095 $ignores = array(); 3096 $ignores[] = $this->string_quoting; 3042 3097 $ignores[] = $this->identifier_quoting; 3043 3098 $ignores = array_merge($ignores, $this->sql_comments); 3044 3099 3045 3100 foreach ($ignores as $ignore) { 3046 3101 if (!empty($ignore['start'])) { … … 3052 3107 $end_quote = strlen($query) - 1; 3053 3108 } else { 3054 $err = & $this->raiseError(MDB2_ERROR_SYNTAX, null, null,3109 $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_SYNTAX, null, null, 3055 3110 'query with an unterminated text string specified', __FUNCTION__); 3056 3111 return $err; … … 3071 3126 return $position; 3072 3127 } 3073 3128 3074 3129 // }}} 3075 3130 // {{{ function quote($value, $type = null, $quote = true) … … 3092 3147 { 3093 3148 $result = $this->loadModule('Datatype', null, true); 3094 if ( PEAR::isError($result)) {3149 if (MDB2::isError($result)) { 3095 3150 return $result; 3096 3151 } … … 3118 3173 { 3119 3174 $result = $this->loadModule('Datatype', null, true); 3120 if ( PEAR::isError($result)) {3175 if (MDB2::isError($result)) { 3121 3176 return $result; 3122 3177 } … … 3140 3195 { 3141 3196 $result = $this->loadModule('Datatype', null, true); 3142 if ( PEAR::isError($result)) {3197 if (MDB2::isError($result)) { 3143 3198 return $result; 3144 3199 } … … 3166 3221 return $this->supported[$feature]; 3167 3222 } 3168 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,3223 return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 3169 3224 "unknown support feature $feature", __FUNCTION__); 3170 3225 } … … 3221 3276 function nextID($seq_name, $ondemand = true) 3222 3277 { 3223 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,3278 return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 3224 3279 'method not implemented', __FUNCTION__); 3225 3280 } … … 3241 3296 function lastInsertID($table = null, $field = null) 3242 3297 { 3243 return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,3298 return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 3244 3299 'method not implemented', __FUNCTION__); 3245 3300 } … … 3396 3451 3397 3452 // }}} 3453 // {{{ function delExpect($error_code) 3454 3455 /** 3456 * This method deletes all occurences of the specified element from 3457 * the expected error codes stack. 3458 * 3459 * @param mixed $error_code error code that should be deleted 3460 * @return mixed list of error codes that were deleted or error 3461 * 3462 * @uses PEAR::delExpect() 3463 */ 3464 public function delExpect($error_code) 3465 { 3466 return $this->pear->delExpect($error_code); 3467 } 3468 3469 // }}} 3470 // {{{ function expectError($code) 3471 3472 /** 3473 * This method is used to tell which errors you expect to get. 3474 * Expected errors are always returned with error mode 3475 * PEAR_ERROR_RETURN. Expected error codes are stored in a stack, 3476 * and this method pushes a new element onto it. The list of 3477 * expected errors are in effect until they are popped off the 3478 * stack with the popExpect() method. 3479 * 3480 * Note that this method can not be called statically 3481 * 3482 * @param mixed $code a single error code or an array of error codes to expect 3483 * 3484 * @return int the new depth of the "expected errors" stack 3485 * 3486 * @uses PEAR::expectError() 3487 */ 3488 public function expectError($code = '*') 3489 { 3490 return $this->pear->expectError($code); 3491 } 3492 3493 // }}} 3494 // {{{ function getStaticProperty($class, $var) 3495 3496 /** 3497 * If you have a class that's mostly/entirely static, and you need static 3498 * properties, you can use this method to simulate them. Eg. in your method(s) 3499 * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar'); 3500 * You MUST use a reference, or they will not persist! 3501 * 3502 * @param string $class The calling classname, to prevent clashes 3503 * @param string $var The variable to retrieve. 3504 * @return mixed A reference to the variable. If not set it will be 3505 * auto initialised to NULL. 3506 * 3507 * @uses PEAR::getStaticProperty() 3508 */ 3509 public function &getStaticProperty($class, $var) 3510 { 3511 $tmp =& $this->pear->getStaticProperty($class, $var); 3512 return $tmp; 3513 } 3514 3515 // }}} 3516 // {{{ function popErrorHandling() 3517 3518 /** 3519 * Pop the last error handler used 3520 * 3521 * @return bool Always true 3522 * 3523 * @see PEAR::pushErrorHandling 3524 * @uses PEAR::popErrorHandling() 3525 */ 3526 public function popErrorHandling() 3527 { 3528 return $this->pear->popErrorHandling(); 3529 } 3530 3531 // }}} 3532 // {{{ function popExpect() 3533 3534 /** 3535 * This method pops one element off the expected error codes 3536 * stack. 3537 * 3538 * @return array the list of error codes that were popped 3539 * 3540 * @uses PEAR::popExpect() 3541 */ 3542 public function popExpect() 3543 { 3544 return $this->pear->popExpect(); 3545 } 3546 3547 // }}} 3548 // {{{ function pushErrorHandling($mode, $options = null) 3549 3550 /** 3551 * Push a new error handler on top of the error handler options stack. With this 3552 * you can easily override the actual error handler for some code and restore 3553 * it later with popErrorHandling. 3554 * 3555 * @param mixed $mode (same as setErrorHandling) 3556 * @param mixed $options (same as setErrorHandling) 3557 * 3558 * @return bool Always true 3559 * 3560 * @see PEAR::setErrorHandling 3561 * @uses PEAR::pushErrorHandling() 3562 */ 3563 public function pushErrorHandling($mode, $options = null) 3564 { 3565 return $this->pear->pushErrorHandling($mode, $options); 3566 } 3567 3568 // }}} 3569 // {{{ function registerShutdownFunc($func, $args = array()) 3570 3571 /** 3572 * Use this function to register a shutdown method for static 3573 * classes. 3574 * 3575 * @param mixed $func The function name (or array of class/method) to call 3576 * @param mixed $args The arguments to pass to the function 3577 * @return void 3578 * 3579 * @uses PEAR::registerShutdownFunc() 3580 */ 3581 public function registerShutdownFunc($func, $args = array()) 3582 { 3583 return $this->pear->registerShutdownFunc($func, $args); 3584 } 3585 3586 // }}} 3587 // {{{ function setErrorHandling($mode = null, $options = null) 3588 3589 /** 3590 * Sets how errors generated by this object should be handled. 3591 * Can be invoked both in objects and statically. If called 3592 * statically, setErrorHandling sets the default behaviour for all 3593 * PEAR objects. If called in an object, setErrorHandling sets 3594 * the default behaviour for that object. 3595 * 3596 * @param int $mode 3597 * One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, 3598 * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE, 3599 * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION. 3600 * 3601 * @param mixed $options 3602 * When $mode is PEAR_ERROR_TRIGGER, this is the error level (one 3603 * of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). 3604 * 3605 * When $mode is PEAR_ERROR_CALLBACK, this parameter is expected 3606 * to be the callback function or method. A callback 3607 * function is a string with the name of the function, a 3608 * callback method is an array of two elements: the element 3609 * at index 0 is the object, and the element at index 1 is 3610 * the name of the method to call in the object. 3611 * 3612 * When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is 3613 * a printf format string used when printing the error 3614 * message. 3615 * 3616 * @access public 3617 * @return void 3618 * @see PEAR_ERROR_RETURN 3619 * @see PEAR_ERROR_PRINT 3620 * @see PEAR_ERROR_TRIGGER 3621 * @see PEAR_ERROR_DIE 3622 * @see PEAR_ERROR_CALLBACK 3623 * @see PEAR_ERROR_EXCEPTION 3624 * 3625 * @since PHP 4.0.5 3626 * @uses PEAR::setErrorHandling($mode, $options) 3627 */ 3628 public function setErrorHandling($mode = null, $options = null) 3629 { 3630 return $this->pear->setErrorHandling($mode, $options); 3631 } 3632 3633 /** 3634 * @uses PEAR::staticPopErrorHandling() 3635 */ 3636 public function staticPopErrorHandling() 3637 { 3638 return $this->pear->staticPopErrorHandling(); 3639 } 3640 3641 // }}} 3642 // {{{ function staticPushErrorHandling($mode, $options = null) 3643 3644 /** 3645 * @uses PEAR::staticPushErrorHandling($mode, $options) 3646 */ 3647 public function staticPushErrorHandling($mode, $options = null) 3648 { 3649 return $this->pear->staticPushErrorHandling($mode, $options); 3650 } 3651 3652 // }}} 3653 // {{{ function &throwError($message = null, $code = null, $userinfo = null) 3654 3655 /** 3656 * Simpler form of raiseError with fewer options. In most cases 3657 * message, code and userinfo are enough. 3658 * 3659 * @param mixed $message a text error message or a PEAR error object 3660 * 3661 * @param int $code a numeric error code (it is up to your class 3662 * to define these if you want to use codes) 3663 * 3664 * @param string $userinfo If you need to pass along for example debug 3665 * information, this parameter is meant for that. 3666 * 3667 * @return object a PEAR error object 3668 * @see PEAR::raiseError 3669 * @uses PEAR::&throwError() 3670 */ 3671 public function &throwError($message = null, $code = null, $userinfo = null) 3672 { 3673 $tmp =& $this->pear->throwError($message, $code, $userinfo); 3674 return $tmp; 3675 } 3676 3677 // }}} 3398 3678 } 3399 3679 … … 3426 3706 // {{{ Variables (Properties) 3427 3707 3428 var $db; 3429 var $result; 3430 var $rownum = -1; 3431 var $types = array(); 3432 var $values = array(); 3433 var $offset; 3434 var $offset_count = 0; 3435 var $limit; 3436 var $column_names; 3437 3438 // }}} 3439 // {{{ constructor: function __construct(&$db, &$result, $limit = 0, $offset = 0) 3708 public $db; 3709 public $result; 3710 public $rownum = -1; 3711 public $types = array(); 3712 public $types_assoc = array(); 3713 public $values = array(); 3714 public $offset; 3715 public $offset_count = 0; 3716 public $limit; 3717 public $column_names; 3718 3719 // }}} 3720 // {{{ constructor: function __construct($db, &$result, $limit = 0, $offset = 0) 3440 3721 3441 3722 /** 3442 3723 * Constructor 3443 3724 */ 3444 function __construct( &$db, &$result, $limit = 0, $offset = 0)3445 { 3446 $this->db = &$db;3447 $this->result = &$result;3725 function __construct($db, &$result, $limit = 0, $offset = 0) 3726 { 3727 $this->db = $db; 3728 $this->result = $result; 3448 3729 $this->offset = $offset; 3449 3730 $this->limit = max(0, $limit - 1); 3450 }3451 3452 // }}}3453 // {{{ function MDB2_Result_Common(&$db, &$result, $limit = 0, $offset = 0)3454 3455 /**3456 * PHP 4 Constructor3457 */3458 function MDB2_Result_Common(&$db, &$result, $limit = 0, $offset = 0)3459 {3460 $this->__construct($db, $result, $limit, $offset);3461 3731 } 3462 3732 … … 3488 3758 { 3489 3759 $load = $this->db->loadModule('Datatype', null, true); 3490 if ( PEAR::isError($load)) {3760 if (MDB2::isError($load)) { 3491 3761 return $load; 3492 3762 } 3493 3763 $types = $this->db->datatype->checkResultTypes($types); 3494 if ( PEAR::isError($types)) {3764 if (MDB2::isError($types)) { 3495 3765 return $types; 3496 3766 } 3497 $this->types = $types; 3767 foreach ($types as $key => $value) { 3768 if (is_numeric($key)) { 3769 $this->types[$key] = $value; 3770 } else { 3771 $this->types_assoc[$key] = $value; 3772 } 3773 } 3498 3774 return MDB2_OK; 3499 3775 } … … 3515 3791 $target_rownum = $rownum - 1; 3516 3792 if ($this->rownum > $target_rownum) { 3517 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,3793 return MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 3518 3794 'seeking to previous rows not implemented', __FUNCTION__); 3519 3795 } … … 3537 3813 * @access public 3538 3814 */ 3539 function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)3540 { 3541 $err = & $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,3815 function fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) 3816 { 3817 $err = MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 3542 3818 'method not implemented', __FUNCTION__); 3543 3819 return $err; … … 3560 3836 $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC; 3561 3837 $row = $this->fetchRow($fetchmode, $rownum); 3562 if (!is_array($row) || PEAR::isError($row)) {3838 if (!is_array($row) || MDB2::isError($row)) { 3563 3839 return $row; 3564 3840 } 3565 3841 if (!array_key_exists($colnum, $row)) { 3566 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,3842 return MDB2::raiseError(MDB2_ERROR_TRUNCATED, null, null, 3567 3843 'column is not defined in the result set: '.$colnum, __FUNCTION__); 3568 3844 } … … 3588 3864 if (is_array($row)) { 3589 3865 if (!array_key_exists($colnum, $row)) { 3590 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,3866 return MDB2::raiseError(MDB2_ERROR_TRUNCATED, null, null, 3591 3867 'column is not defined in the result set: '.$colnum, __FUNCTION__); 3592 3868 } … … 3595 3871 } while (is_array($row = $this->fetchRow($fetchmode))); 3596 3872 } 3597 if ( PEAR::isError($row)) {3873 if (MDB2::isError($row)) { 3598 3874 return $row; 3599 3875 } … … 3632 3908 $all = array(); 3633 3909 $row = $this->fetchRow($fetchmode); 3634 if ( PEAR::isError($row)) {3910 if (MDB2::isError($row)) { 3635 3911 return $row; 3636 3912 } elseif (!$row) { … … 3639 3915 3640 3916 $shift_array = $rekey ? false : null; 3641 if ( !is_null($shift_array)) {3917 if (null !== $shift_array) { 3642 3918 if (is_object($row)) { 3643 3919 $colnum = count(get_object_vars($row)); … … 3646 3922 } 3647 3923 if ($colnum < 2) { 3648 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,3924 return MDB2::raiseError(MDB2_ERROR_TRUNCATED, null, null, 3649 3925 'rekey feature requires atleast 2 column', __FUNCTION__); 3650 3926 } … … 3659 3935 unset($row->{$key}); 3660 3936 } else { 3661 if ($fetchmode & MDB2_FETCHMODE_ASSOC) { 3937 if ( $fetchmode == MDB2_FETCHMODE_ASSOC 3938 || $fetchmode == MDB2_FETCHMODE_OBJECT 3939 ) { 3662 3940 $key = reset($row); 3663 3941 unset($row[key($row)]); … … 3675 3953 } 3676 3954 } while (($row = $this->fetchRow($fetchmode))); 3677 } elseif ($fetchmode &MDB2_FETCHMODE_FLIPPED) {3955 } elseif ($fetchmode == MDB2_FETCHMODE_FLIPPED) { 3678 3956 do { 3679 3957 foreach ($row as $key => $val) { … … 3715 3993 function numRows() 3716 3994 { 3717 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,3995 return MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 3718 3996 'method not implemented', __FUNCTION__); 3719 3997 } … … 3731 4009 function nextResult() 3732 4010 { 3733 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,4011 return MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 3734 4012 'method not implemented', __FUNCTION__); 3735 4013 } … … 3755 4033 if (!isset($this->column_names)) { 3756 4034 $result = $this->_getColumnNames(); 3757 if ( PEAR::isError($result)) {4035 if (MDB2::isError($result)) { 3758 4036 return $result; 3759 4037 } … … 3781 4059 function _getColumnNames() 3782 4060 { 3783 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,4061 return MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 3784 4062 'method not implemented', __FUNCTION__); 3785 4063 } … … 3798 4076 function numCols() 3799 4077 { 3800 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,4078 return MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 3801 4079 'method not implemented', __FUNCTION__); 3802 4080 } … … 3845 4123 } 3846 4124 $this->values[$column] =& $value; 3847 if ( !is_null($type)) {4125 if (null !== $type) { 3848 4126 $this->types[$column] = $type; 3849 4127 } … … 3920 4198 3921 4199 // }}} 3922 // {{{ function MDB2_Row(&$row)3923 3924 /**3925 * PHP 4 Constructor3926 *3927 * @param resource row data as array3928 */3929 function MDB2_Row(&$row)3930 {3931 $this->__construct($row);3932 }3933 3934 // }}}3935 4200 } 3936 4201 … … 3960 4225 3961 4226 // }}} 3962 // {{{ constructor: function __construct( &$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)4227 // {{{ constructor: function __construct($db, $statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null) 3963 4228 3964 4229 /** 3965 4230 * Constructor 3966 4231 */ 3967 function __construct( &$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)3968 { 3969 $this->db = &$db;3970 $this->statement = &$statement;4232 function __construct($db, $statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null) 4233 { 4234 $this->db = $db; 4235 $this->statement = $statement; 3971 4236 $this->positions = $positions; 3972 4237 $this->query = $query; … … 3979 4244 3980 4245 // }}} 3981 // {{{ function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)3982 3983 /**3984 * PHP 4 Constructor3985 */3986 function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)3987 {3988 $this->__construct($db, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);3989 }3990 3991 // }}}3992 4246 // {{{ function bindValue($parameter, &$value, $type = null) 3993 4247 … … 4008 4262 { 4009 4263 if (!is_numeric($parameter)) { 4010 $parameter = preg_replace('/^:(.*)$/', '\\1', $parameter); 4264 if (strpos($parameter, ':') === 0) { 4265 $parameter = substr($parameter, 1); 4266 } 4011 4267 } 4012 4268 if (!in_array($parameter, $this->positions)) { 4013 return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,4269 return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 4014 4270 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__); 4015 4271 } 4016 4272 $this->values[$parameter] = $value; 4017 if ( !is_null($type)) {4273 if (null !== $type) { 4018 4274 $this->types[$parameter] = $type; 4019 4275 } … … 4041 4297 $types = is_array($types) ? array_values($types) : array_fill(0, count($values), null); 4042 4298 $parameters = array_keys($values); 4299 $this->db->pushErrorHandling(PEAR_ERROR_RETURN); 4300 $this->db->expectError(MDB2_ERROR_NOT_FOUND); 4043 4301 foreach ($parameters as $key => $parameter) { 4044 $this->db->pushErrorHandling(PEAR_ERROR_RETURN);4045 $this->db->expectError(MDB2_ERROR_NOT_FOUND);4046 4302 $err = $this->bindValue($parameter, $values[$parameter], $types[$key]); 4047 $this->db->popExpect(); 4048 $this->db->popErrorHandling(); 4049 if (PEAR::isError($err)) { 4303 if (MDB2::isError($err)) { 4050 4304 if ($err->getCode() == MDB2_ERROR_NOT_FOUND) { 4051 4305 //ignore (extra value for missing placeholder) 4052 4306 continue; 4053 4307 } 4308 $this->db->popExpect(); 4309 $this->db->popErrorHandling(); 4054 4310 return $err; 4055 4311 } 4056 4312 } 4313 $this->db->popExpect(); 4314 $this->db->popErrorHandling(); 4057 4315 return MDB2_OK; 4058 4316 } … … 4077 4335 { 4078 4336 if (!is_numeric($parameter)) { 4079 $parameter = preg_replace('/^:(.*)$/', '\\1', $parameter); 4337 if (strpos($parameter, ':') === 0) { 4338 $parameter = substr($parameter, 1); 4339 } 4080 4340 } 4081 4341 if (!in_array($parameter, $this->positions)) { 4082 return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,4342 return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 4083 4343 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__); 4084 4344 } 4085 4345 $this->values[$parameter] =& $value; 4086 if ( !is_null($type)) {4346 if (null !== $type) { 4087 4347 $this->types[$parameter] = $type; 4088 4348 } … … 4112 4372 foreach ($parameters as $key => $parameter) { 4113 4373 $err = $this->bindParam($parameter, $values[$parameter], $types[$key]); 4114 if ( PEAR::isError($err)) {4374 if (MDB2::isError($err)) { 4115 4375 return $err; 4116 4376 } … … 4135 4395 * @access public 4136 4396 */ 4137 function &execute($values = null, $result_class = true, $result_wrap_class = false)4138 { 4139 if ( is_null($this->positions)) {4140 return $this->db->raiseError(MDB2_ERROR, null, null,4397 function execute($values = null, $result_class = true, $result_wrap_class = false) 4398 { 4399 if (null === $this->positions) { 4400 return MDB2::raiseError(MDB2_ERROR, null, null, 4141 4401 'Prepared statement has already been freed', __FUNCTION__); 4142 4402 } … … 4145 4405 if (!empty($values)) { 4146 4406 $err = $this->bindValueArray($values); 4147 if ( PEAR::isError($err)) {4148 return $this->db->raiseError(MDB2_ERROR, null, null,4407 if (MDB2::isError($err)) { 4408 return MDB2::raiseError(MDB2_ERROR, null, null, 4149 4409 'Binding Values failed with message: ' . $err->getMessage(), __FUNCTION__); 4150 4410 } 4151 4411 } 4152 $result = &$this->_execute($result_class, $result_wrap_class);4412 $result = $this->_execute($result_class, $result_wrap_class); 4153 4413 return $result; 4154 4414 } 4155 4415 4156 4416 // }}} 4157 // {{{ function &_execute($result_class = true, $result_wrap_class = false)4417 // {{{ function _execute($result_class = true, $result_wrap_class = false) 4158 4418 4159 4419 /** … … 4167 4427 * @access private 4168 4428 */ 4169 function &_execute($result_class = true, $result_wrap_class = false)4429 function _execute($result_class = true, $result_wrap_class = false) 4170 4430 { 4171 4431 $this->last_query = $this->query; … … 4174 4434 foreach ($this->positions as $current_position => $parameter) { 4175 4435 if (!array_key_exists($parameter, $this->values)) { 4176 return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,4436 return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 4177 4437 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__); 4178 4438 } … … 4184 4444 $type = !empty($this->types[$parameter]) ? $this->types[$parameter] : null; 4185 4445 $value_quoted = $this->db->quote($value, $type); 4186 if ( PEAR::isError($value_quoted)) {4446 if (MDB2::isError($value_quoted)) { 4187 4447 return $value_quoted; 4188 4448 } … … 4198 4458 $result = $this->db->exec($query); 4199 4459 } else { 4200 $result = &$this->db->query($query, $this->result_types, $result_class, $result_wrap_class);4460 $result = $this->db->query($query, $this->result_types, $result_class, $result_wrap_class); 4201 4461 } 4202 4462 return $result; … … 4215 4475 function free() 4216 4476 { 4217 if ( is_null($this->positions)) {4218 return $this->db->raiseError(MDB2_ERROR, null, null,4477 if (null === $this->positions) { 4478 return MDB2::raiseError(MDB2_ERROR, null, null, 4219 4479 'Prepared statement has already been freed', __FUNCTION__); 4220 4480 } … … 4257 4517 * @access protected 4258 4518 */ 4259 var$db_index;4519 protected $db_index; 4260 4520 4261 4521 // }}} … … 4271 4531 4272 4532 // }}} 4273 // {{{ function MDB2_Module_Common($db_index) 4274 4275 /** 4276 * PHP 4 Constructor 4277 */ 4278 function MDB2_Module_Common($db_index) 4279 { 4280 $this->__construct($db_index); 4281 } 4282 4283 // }}} 4284 // {{{ function &getDBInstance() 4533 // {{{ function getDBInstance() 4285 4534 4286 4535 /** … … 4291 4540 * @access public 4292 4541 */ 4293 function &getDBInstance()4542 function getDBInstance() 4294 4543 { 4295 4544 if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) { 4296 $result = &$GLOBALS['_MDB2_databases'][$this->db_index];4545 $result = $GLOBALS['_MDB2_databases'][$this->db_index]; 4297 4546 } else { 4298 $result = &MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,4547 $result = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 4299 4548 'could not find MDB2 instance'); 4300 4549 }
Note: See TracChangeset
for help on using the changeset viewer.
