ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
MDB2 Class Reference
+ Collaboration diagram for MDB2:

Public Member Functions

 setOptions (&$db, $options)
 set option array in an exiting database object More...
 
 loadClass ($class_name, $debug)
 Loads a PEAR class. More...
 
factory ($dsn, $options=false)
 Create a new MDB2 object for the specified database type. More...
 
connect ($dsn, $options=false)
 Create a new MDB2 connection object and connect to the specified database. More...
 
singleton ($dsn=null, $options=false)
 Returns a MDB2 connection with the requested DSN. More...
 
 loadFile ($file)
 load a file (like 'Date') More...
 
 apiVersion ()
 Return the MDB2 API version. More...
 
raiseError ($code=null, $mode=null, $options=null, $userinfo=null)
 This method is used to communicate an error and invoke error callbacks etc. More...
 
 isError ($data, $code=null)
 Tell whether a value is a MDB2 error. More...
 
 isConnection ($value)
 Tell whether a value is a MDB2 connection. More...
 
 isResult ($value)
 Tell whether a value is a MDB2 result. More...
 
 isResultCommon ($value)
 Tell whether a value is a MDB2 result implementing the common interface. More...
 
 isStatement ($value)
 Tell whether a value is a MDB2 statement interface. More...
 
 errorMessage ($value=null)
 Return a textual error message for a MDB2 error code. More...
 
 parseDSN ($dsn)
 
 fileExists ($file)
 Checks if a file exists in the include path. More...
 

Static Public Member Functions

 classExists ($classname)
 Checks if a class exists without triggering __autoload. More...
 

Detailed Description

Definition at line 265 of file MDB2.php.

Member Function Documentation

◆ apiVersion()

MDB2::apiVersion ( )

Return the MDB2 API version.

Returns
string the MDB2 API version number

@access public

Definition at line 540 of file MDB2.php.

541 {
542 return '2.4.1';
543 }

◆ classExists()

MDB2::classExists (   $classname)
static

Checks if a class exists without triggering __autoload.

Parameters
stringclassname
Returns
bool true success and false on error

@access public

Definition at line 304 of file MDB2.php.

305 {
306 if (version_compare(phpversion(), "5.0", ">=")) {
307 return class_exists($classname, false);
308 }
309 return class_exists($classname);
310 }

Referenced by MDB2_Driver_Common\_wrapResult(), loadClass(), and MDB2_Driver_Common\loadModule().

+ Here is the caller graph for this function:

◆ connect()

& MDB2::connect (   $dsn,
  $options = false 
)

Create a new MDB2 connection object and connect to the specified database.

IMPORTANT: In order for MDB2 to work properly it is necessary that you make sure that you work with a reference of the original object instead of a copy (this is a PHP4 quirk).

For example: $db =& MDB2::connect($dsn); ^^ And not: $db = MDB2::connect($dsn); ^^

Parameters
mixed'data source name', see the MDB2::parseDSN method for a description of the dsn format. Can also be specified as an array of the format returned by MDB2::parseDSN.
arrayAn associative array of option names and their values.
Returns
mixed a newly created MDB2 connection object, or a MDB2 error object on error

@access public

See also
MDB2::parseDSN

Definition at line 431 of file MDB2.php.

432 {
433 $db =& MDB2::factory($dsn, $options);
434 if (PEAR::isError($db)) {
435 return $db;
436 }
437
438 $err = $db->connect();
439 if (PEAR::isError($err)) {
440 $dsn = $db->getDSN('string', 'xxx');
441 $db->disconnect();
442 $err->addUserInfo($dsn);
443 return $err;
444 }
445
446 return $db;
447 }
& factory($dsn, $options=false)
Create a new MDB2 object for the specified database type.
Definition: MDB2.php:374
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
if(!is_array($argv)) $options

References $options, factory(), and PEAR\isError().

Referenced by Auth_Container_MDB2\_connect(), ilDBConnections\connectDB(), ilDBConnections\connectHost(), ilDB\connectHost(), ilDB\doConnect(), ilDBMySQL\doConnect(), ilDBOracle\doConnect(), and Log_mdb2\open().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ errorMessage()

MDB2::errorMessage (   $value = null)

Return a textual error message for a MDB2 error code.

Parameters
int|arrayinteger error code, null to get the current error code-message map, or an array with a new error code-message map
Returns
string error message, or false if the error code was not recognized

@access public

Definition at line 692 of file MDB2.php.

693 {
694 static $errorMessages;
695
696 if (is_array($value)) {
697 $errorMessages = $value;
698 return MDB2_OK;
699 }
700
701 if (!isset($errorMessages)) {
702 $errorMessages = array(
703 MDB2_OK => 'no error',
704 MDB2_ERROR => 'unknown error',
705 MDB2_ERROR_ALREADY_EXISTS => 'already exists',
706 MDB2_ERROR_CANNOT_CREATE => 'can not create',
707 MDB2_ERROR_CANNOT_ALTER => 'can not alter',
708 MDB2_ERROR_CANNOT_REPLACE => 'can not replace',
709 MDB2_ERROR_CANNOT_DELETE => 'can not delete',
710 MDB2_ERROR_CANNOT_DROP => 'can not drop',
711 MDB2_ERROR_CONSTRAINT => 'constraint violation',
712 MDB2_ERROR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
713 MDB2_ERROR_DIVZERO => 'division by zero',
714 MDB2_ERROR_INVALID => 'invalid',
715 MDB2_ERROR_INVALID_DATE => 'invalid date or time',
716 MDB2_ERROR_INVALID_NUMBER => 'invalid number',
717 MDB2_ERROR_MISMATCH => 'mismatch',
718 MDB2_ERROR_NODBSELECTED => 'no database selected',
719 MDB2_ERROR_NOSUCHFIELD => 'no such field',
720 MDB2_ERROR_NOSUCHTABLE => 'no such table',
721 MDB2_ERROR_NOT_CAPABLE => 'MDB2 backend not capable',
722 MDB2_ERROR_NOT_FOUND => 'not found',
723 MDB2_ERROR_NOT_LOCKED => 'not locked',
724 MDB2_ERROR_SYNTAX => 'syntax error',
725 MDB2_ERROR_UNSUPPORTED => 'not supported',
726 MDB2_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
727 MDB2_ERROR_INVALID_DSN => 'invalid DSN',
728 MDB2_ERROR_CONNECT_FAILED => 'connect failed',
729 MDB2_ERROR_NEED_MORE_DATA => 'insufficient data supplied',
730 MDB2_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
731 MDB2_ERROR_NOSUCHDB => 'no such database',
732 MDB2_ERROR_ACCESS_VIOLATION => 'insufficient permissions',
733 MDB2_ERROR_LOADMODULE => 'error while including on demand module',
734 MDB2_ERROR_TRUNCATED => 'truncated',
735 MDB2_ERROR_DEADLOCK => 'deadlock detected',
736 );
737 }
738
739 if (is_null($value)) {
740 return $errorMessages;
741 }
742
743 if (PEAR::isError($value)) {
744 $value = $value->getCode();
745 }
746
747 return isset($errorMessages[$value]) ?
748 $errorMessages[$value] : $errorMessages[MDB2_ERROR];
749 }
const MDB2_ERROR_ACCESS_VIOLATION
Definition: MDB2.php:94
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:73
const MDB2_ERROR_NODBSELECTED
Definition: MDB2.php:81
const MDB2_ERROR_DEADLOCK
Definition: MDB2.php:97
const MDB2_ERROR_INVALID_DATE
Definition: MDB2.php:79
const MDB2_ERROR_CANNOT_DELETE
Definition: MDB2.php:83
const MDB2_ERROR_INVALID
Definition: MDB2.php:75
const MDB2_ERROR_CONSTRAINT_NOT_NULL
Definition: MDB2.php:96
const MDB2_OK
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these.
Definition: MDB2.php:67
const MDB2_ERROR_MISMATCH
Definition: MDB2.php:74
const MDB2_ERROR_SYNTAX
Definition: MDB2.php:69
const MDB2_ERROR_NOT_LOCKED
Definition: MDB2.php:88
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:71
const MDB2_ERROR_VALUE_COUNT_ON_ROW
Definition: MDB2.php:89
const MDB2_ERROR_CANNOT_CREATE
Definition: MDB2.php:82
const MDB2_ERROR_INVALID_NUMBER
Definition: MDB2.php:78
const MDB2_ERROR_EXTENSION_NOT_FOUND
Definition: MDB2.php:92
const MDB2_ERROR_LOADMODULE
Definition: MDB2.php:101
const MDB2_ERROR_INVALID_DSN
Definition: MDB2.php:90
const MDB2_ERROR_NOT_CAPABLE
Definition: MDB2.php:76
const MDB2_ERROR_ALREADY_EXISTS
Definition: MDB2.php:72
const MDB2_ERROR_DIVZERO
Definition: MDB2.php:80
const MDB2_ERROR_CONSTRAINT
Definition: MDB2.php:70
const MDB2_ERROR_NOSUCHFIELD
Definition: MDB2.php:86
const MDB2_ERROR_CANNOT_ALTER
Definition: MDB2.php:98
const MDB2_ERROR_TRUNCATED
Definition: MDB2.php:77
const MDB2_ERROR_NEED_MORE_DATA
Definition: MDB2.php:87
const MDB2_ERROR
Definition: MDB2.php:68
const MDB2_ERROR_NOSUCHTABLE
Definition: MDB2.php:85
const MDB2_ERROR_CONNECT_FAILED
Definition: MDB2.php:91
const MDB2_ERROR_NOSUCHDB
Definition: MDB2.php:93
const MDB2_ERROR_CANNOT_REPLACE
Definition: MDB2.php:95
const MDB2_ERROR_CANNOT_DROP
Definition: MDB2.php:84

References PEAR\isError(), MDB2_ERROR, MDB2_ERROR_ACCESS_VIOLATION, MDB2_ERROR_ALREADY_EXISTS, MDB2_ERROR_CANNOT_ALTER, MDB2_ERROR_CANNOT_CREATE, MDB2_ERROR_CANNOT_DELETE, MDB2_ERROR_CANNOT_DROP, MDB2_ERROR_CANNOT_REPLACE, MDB2_ERROR_CONNECT_FAILED, MDB2_ERROR_CONSTRAINT, MDB2_ERROR_CONSTRAINT_NOT_NULL, MDB2_ERROR_DEADLOCK, MDB2_ERROR_DIVZERO, MDB2_ERROR_EXTENSION_NOT_FOUND, MDB2_ERROR_INVALID, MDB2_ERROR_INVALID_DATE, MDB2_ERROR_INVALID_DSN, MDB2_ERROR_INVALID_NUMBER, MDB2_ERROR_LOADMODULE, MDB2_ERROR_MISMATCH, MDB2_ERROR_NEED_MORE_DATA, MDB2_ERROR_NODBSELECTED, MDB2_ERROR_NOSUCHDB, MDB2_ERROR_NOSUCHFIELD, MDB2_ERROR_NOSUCHTABLE, MDB2_ERROR_NOT_CAPABLE, MDB2_ERROR_NOT_FOUND, MDB2_ERROR_NOT_LOCKED, MDB2_ERROR_SYNTAX, MDB2_ERROR_TRUNCATED, MDB2_ERROR_UNSUPPORTED, MDB2_ERROR_VALUE_COUNT_ON_ROW, and MDB2_OK.

Referenced by MDB2_Error\MDB2_Error().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ factory()

& MDB2::factory (   $dsn,
  $options = false 
)

Create a new MDB2 object for the specified database type.

IMPORTANT: In order for MDB2 to work properly it is necessary that you make sure that you work with a reference of the original object instead of a copy (this is a PHP4 quirk).

For example: $db =& MDB2::factory($dsn); ^^ And not: $db = MDB2::factory($dsn);

Parameters
mixed'data source name', see the MDB2::parseDSN method for a description of the dsn format. Can also be specified as an array of the format returned by MDB2::parseDSN.
arrayAn associative array of option names and their values.
Returns
mixed a newly created MDB2 object, or false on error

@access public

Definition at line 374 of file MDB2.php.

375 {
376 $dsninfo = MDB2::parseDSN($dsn);
377 if (empty($dsninfo['phptype'])) {
379 null, null, 'no RDBMS driver specified');
380 return $err;
381 }
382 $class_name = 'MDB2_Driver_'.$dsninfo['phptype'];
383
384 $debug = (!empty($options['debug']));
385 $err = MDB2::loadClass($class_name, $debug);
386 if (PEAR::isError($err)) {
387 return $err;
388 }
389
390 $db =& new $class_name();
391 $db->setDSN($dsninfo);
392 $err = MDB2::setOptions($db, $options);
393 if (PEAR::isError($err)) {
394 return $err;
395 }
396
397 return $db;
398 }
parseDSN($dsn)
Definition: MDB2.php:791
loadClass($class_name, $debug)
Loads a PEAR class.
Definition: MDB2.php:325
setOptions(&$db, $options)
set option array in an exiting database object
Definition: MDB2.php:279
& raiseError($code=null, $mode=null, $options=null, $userinfo=null)
This method is used to communicate an error and invoke error callbacks etc.
Definition: MDB2.php:572

References $options, PEAR\isError(), loadClass(), MDB2_ERROR_NOT_FOUND, parseDSN(), raiseError(), and setOptions().

Referenced by connect(), and singleton().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fileExists()

MDB2::fileExists (   $file)

Checks if a file exists in the include path.

Parameters
stringfilename
Returns
bool true success and false on error

@access public

Definition at line 921 of file MDB2.php.

922 {
923 // safe_mode does notwork with is_readable()
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)) {
928 return true;
929 }
930 }
931 } else {
932 $fp = @fopen($file, 'r', true);
933 if (is_resource($fp)) {
934 @fclose($fp);
935 return true;
936 }
937 }
938 return false;
939 }
print $file
$dirs

References $dirs, and $file.

Referenced by loadClass(), loadFile(), and MDB2_Driver_Common\loadModule().

+ Here is the caller graph for this function:

◆ isConnection()

MDB2::isConnection (   $value)

Tell whether a value is a MDB2 connection.

Parameters
mixedvalue to test
Returns
bool whether $value is a MDB2 connection

@access public

Definition at line 621 of file MDB2.php.

622 {
623 return is_a($value, 'MDB2_Driver_Common');
624 }

◆ isError()

MDB2::isError (   $data,
  $code = null 
)

Tell whether a value is a MDB2 error.

Parameters
mixedthe value to test
intif is an error object, return true only if $code is a string and $db->getMessage() == $code or $code is an integer and $db->getCode() == $code
Returns
bool true if parameter is an error

@access public

Definition at line 594 of file MDB2.php.

595 {
596 if (is_a($data, 'MDB2_Error')) {
597 if (is_null($code)) {
598 return true;
599 } elseif (is_string($code)) {
600 return $data->getMessage() === $code;
601 } else {
602 $code = (array)$code;
603 return in_array($data->getCode(), $code);
604 }
605 }
606 return false;
607 }
$data
$code
Definition: example_050.php:99

References $code, and $data.

Referenced by Auth_Container_MDB2\_connect(), Auth_Container_MDB2\addUser(), ilMySQLAbstraction\alterTable(), Auth_Container_MDB2\changePassword(), ilClient\checkDatabaseExists(), ilClient\checkDatabaseHost(), ilDB\connect(), ilDB\connectHost(), ilSetup\createDatabase(), ilDBUpdate\execQuery(), Auth_Container_MDB2\fetchData(), ilDBOracle\getDBVersion(), ilDB\getLastInsertId(), ilDB\getOne(), ilDB\handleError(), ilDB\isDbError(), ilDB\listSequences(), ilDB\listTables(), Auth_Container_MDB2\listUsers(), Auth_Container_MDB2\removeUser(), and ilDB\tableColumnExists().

+ Here is the caller graph for this function:

◆ isResult()

MDB2::isResult (   $value)

Tell whether a value is a MDB2 result.

Parameters
mixedvalue to test
Returns
bool whether $value is a MDB2 result

@access public

Definition at line 638 of file MDB2.php.

639 {
640 return is_a($value, 'MDB2_Result');
641 }

◆ isResultCommon()

MDB2::isResultCommon (   $value)

Tell whether a value is a MDB2 result implementing the common interface.

Parameters
mixedvalue to test
Returns
bool whether $value is a MDB2 result implementing the common interface

@access public

Definition at line 655 of file MDB2.php.

656 {
657 return is_a($value, 'MDB2_Result_Common');
658 }

Referenced by MDB2_Driver_Common\_wrapResult(), MDB2_Extended\getAll(), MDB2_Extended\getAssoc(), MDB2_Extended\getCol(), MDB2_Extended\getOne(), MDB2_Extended\getRow(), MDB2_Driver_Manager_pgsql\listDatabases(), MDB2_Driver_Manager_pgsql\listUsers(), MDB2_Driver_Common\queryAll(), MDB2_Driver_Common\queryCol(), MDB2_Driver_Common\queryOne(), MDB2_Driver_Common\queryRow(), MDB2_Driver_Reverse_mysql\tableInfo(), MDB2_Driver_Reverse_mysqli\tableInfo(), MDB2_Driver_Reverse_oci8\tableInfo(), and MDB2_Driver_Reverse_pgsql\tableInfo().

+ Here is the caller graph for this function:

◆ isStatement()

MDB2::isStatement (   $value)

Tell whether a value is a MDB2 statement interface.

Parameters
mixedvalue to test
Returns
bool whether $value is a MDB2 statement interface

@access public

Definition at line 672 of file MDB2.php.

673 {
674 return is_a($value, 'MDB2_Statement');
675 }

◆ loadClass()

MDB2::loadClass (   $class_name,
  $debug 
)

Loads a PEAR class.

Parameters
stringclassname to load
boolif errors should be suppressed
Returns
mixed true success or PEAR_Error on failure

@access public

Definition at line 325 of file MDB2.php.

326 {
327 if (!MDB2::classExists($class_name)) {
328 $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php';
329 if ($debug) {
330 $include = include_once($file_name);
331 } else {
332 $include = @include_once($file_name);
333 }
334 if (!$include) {
335 if (!MDB2::fileExists($file_name)) {
336 $msg = "unable to find package '$class_name' file '$file_name'";
337 } else {
338 $msg = "unable to load class '$class_name' from file '$file_name'";
339 }
340 $err =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg);
341 return $err;
342 }
343 }
344 return MDB2_OK;
345 }
fileExists($file)
Checks if a file exists in the include path.
Definition: MDB2.php:921
classExists($classname)
Checks if a class exists without triggering __autoload.
Definition: MDB2.php:304

References classExists(), fileExists(), MDB2_ERROR_NOT_FOUND, MDB2_OK, and raiseError().

Referenced by factory(), and MDB2_Driver_Common\loadModule().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadFile()

MDB2::loadFile (   $file)

load a file (like 'Date')

Parameters
stringname of the file in the MDB2 directory (without '.php')
Returns
string name of the file that was included

@access public

Definition at line 516 of file MDB2.php.

517 {
518 $file_name = 'MDB2'.DIRECTORY_SEPARATOR.$file.'.php';
519 if (!MDB2::fileExists($file_name)) {
520 return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
521 'unable to find: '.$file_name);
522 }
523 if (!include_once($file_name)) {
524 return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
525 'unable to load driver class: '.$file_name);
526 }
527 return $file_name;
528 }

References fileExists(), MDB2_ERROR_NOT_FOUND, and raiseError().

+ Here is the call graph for this function:

◆ parseDSN()

MDB2::parseDSN (   $dsn)

Definition at line 791 of file MDB2.php.

792 {
793 $parsed = $GLOBALS['_MDB2_dsninfo_default'];
794
795 if (is_array($dsn)) {
796 $dsn = array_merge($parsed, $dsn);
797 if (!$dsn['dbsyntax']) {
798 $dsn['dbsyntax'] = $dsn['phptype'];
799 }
800 return $dsn;
801 }
802
803 // Find phptype and dbsyntax
804 if (($pos = strpos($dsn, '://')) !== false) {
805 $str = substr($dsn, 0, $pos);
806 $dsn = substr($dsn, $pos + 3);
807 } else {
808 $str = $dsn;
809 $dsn = null;
810 }
811
812 // Get phptype and dbsyntax
813 // $str => phptype(dbsyntax)
814 if (preg_match('|^(.+?)\‍((.*?)\‍)$|', $str, $arr)) {
815 $parsed['phptype'] = $arr[1];
816 $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
817 } else {
818 $parsed['phptype'] = $str;
819 $parsed['dbsyntax'] = $str;
820 }
821
822 if (!count($dsn)) {
823 return $parsed;
824 }
825
826 // Get (if found): username and password
827 // $dsn => username:password@protocol+hostspec/database
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));
834 } else {
835 $parsed['username'] = rawurldecode($str);
836 }
837 }
838
839 // Find protocol and hostspec
840
841 // $dsn => proto(proto_opts)/database
842 if (preg_match('|^([^(]+)\‍((.*?)\‍)/?(.*?)$|', $dsn, $match)) {
843 $proto = $match[1];
844 $proto_opts = $match[2] ? $match[2] : false;
845 $dsn = $match[3];
846
847 // $dsn => protocol+hostspec/database (old format)
848 } else {
849 if (strpos($dsn, '+') !== false) {
850 list($proto, $dsn) = explode('+', $dsn, 2);
851 }
852 if ( strpos($dsn, '//') === 0
853 && strpos($dsn, '/', 2) !== false
854 && $parsed['phptype'] == 'oci8'
855 ) {
856 //oracle's "Easy Connect" syntax:
857 //"username/password@[//]host[:port][/service_name]"
858 //e.g. "scott/tiger@//mymachine:1521/oracle"
859 $proto_opts = $dsn;
860 $dsn = null;
861 } elseif (strpos($dsn, '/') !== false) {
862 list($proto_opts, $dsn) = explode('/', $dsn, 2);
863 } else {
864 $proto_opts = $dsn;
865 $dsn = null;
866 }
867 }
868
869 // process the different protocol options
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);
874 }
875 if ($parsed['protocol'] == 'tcp') {
876 $parsed['hostspec'] = $proto_opts;
877 } elseif ($parsed['protocol'] == 'unix') {
878 $parsed['socket'] = $proto_opts;
879 }
880
881 // Get dabase if any
882 // $dsn => database
883 if ($dsn) {
884 // /database
885 if (($pos = strpos($dsn, '?')) === false) {
886 $parsed['database'] = $dsn;
887 // /database?param1=value1&param2=value2
888 } else {
889 $parsed['database'] = substr($dsn, 0, $pos);
890 $dsn = substr($dsn, $pos + 1);
891 if (strpos($dsn, '&') !== false) {
892 $opts = explode('&', $dsn);
893 } else { // database?param1=value1
894 $opts = array($dsn);
895 }
896 foreach ($opts as $opt) {
897 list($key, $value) = explode('=', $opt);
898 if (!isset($parsed[$key])) {
899 // don't allow params overwrite
900 $parsed[$key] = rawurldecode($value);
901 }
902 }
903 }
904 }
905
906 return $parsed;
907 }
$GLOBALS['_MDB2_databases']
These are global variables that are used to track the various class instances.
Definition: MDB2.php:219

References $GLOBALS.

Referenced by factory(), MDB2_Driver_Common\setDSN(), and singleton().

+ Here is the caller graph for this function:

◆ raiseError()

& MDB2::raiseError (   $code = null,
  $mode = null,
  $options = null,
  $userinfo = null 
)

This method is used to communicate an error and invoke error callbacks etc.

Basically a wrapper for PEAR::raiseError without the message string.

Parameters
mixedint error code
interror mode, see PEAR_Error docs
mixedIf error mode is PEAR_ERROR_TRIGGER, this is the error level (E_USER_NOTICE etc). If error mode is PEAR_ERROR_CALLBACK, this is the callback function, either as a function name, or as an array of an object and method name. For other error modes this parameter is ignored.
stringExtra debug information. Defaults to the last query and native error code.
Returns
PEAR_Error instance of a PEAR Error object

@access private

See also
PEAR_Error

Definition at line 572 of file MDB2.php.

573 {
574 $err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
575 return $err;
576 }
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
Definition: PEAR.php:524

References $code, $options, and PEAR\raiseError().

Referenced by factory(), MDB2_Module_Common\getDBInstance(), loadClass(), and loadFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setOptions()

MDB2::setOptions ( $db,
  $options 
)

set option array in an exiting database object

Parameters
MDB2_Driver_CommonMDB2 object
arrayAn associative array of option names and their values.
Returns
mixed MDB2_OK or a PEAR Error object

@access public

Definition at line 279 of file MDB2.php.

280 {
281 if (is_array($options)) {
282 foreach ($options as $option => $value) {
283 $test = $db->setOption($option, $value);
284 if (PEAR::isError($test)) {
285 return $test;
286 }
287 }
288 }
289 return MDB2_OK;
290 }
$test
Definition: Utf8Test.php:85

References $options, $test, PEAR\isError(), and MDB2_OK.

Referenced by factory(), and singleton().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ singleton()

& MDB2::singleton (   $dsn = null,
  $options = false 
)

Returns a MDB2 connection with the requested DSN.

A new MDB2 connection object is only created if no object with the requested DSN exists yet.

IMPORTANT: In order for MDB2 to work properly it is necessary that you make sure that you work with a reference of the original object instead of a copy (this is a PHP4 quirk).

For example: $db =& MDB2::singleton($dsn); ^^ And not: $db = MDB2::singleton($dsn); ^^

Parameters
mixed'data source name', see the MDB2::parseDSN method for a description of the dsn format. Can also be specified as an array of the format returned by MDB2::parseDSN.
arrayAn associative array of option names and their values.
Returns
mixed a newly created MDB2 connection object, or a MDB2 error object on error

@access public

See also
MDB2::parseDSN

Definition at line 481 of file MDB2.php.

482 {
483 if ($dsn) {
484 $dsninfo = MDB2::parseDSN($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) {
491 MDB2::setOptions($GLOBALS['_MDB2_databases'][$keys[$i]], $options);
492 return $GLOBALS['_MDB2_databases'][$keys[$i]];
493 }
494 }
495 }
496 } elseif (is_array($GLOBALS['_MDB2_databases']) && reset($GLOBALS['_MDB2_databases'])) {
497 $db =& $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])];
498 return $db;
499 }
500 $db =& MDB2::factory($dsn, $options);
501 return $db;
502 }

References $GLOBALS, $options, factory(), parseDSN(), and setOptions().

Referenced by Log_mdb2\Log_mdb2().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: