ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 270 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 545 of file MDB2.php.

546 {
547 return '2.4.1';
548 }

◆ 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 309 of file MDB2.php.

310 {
311 if (version_compare(phpversion(), "5.0", ">=")) {
312 return class_exists($classname, false);
313 }
314 return class_exists($classname);
315 }

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 436 of file MDB2.php.

437 {
438 $db =& MDB2::factory($dsn, $options);
439 if (PEAR::isError($db)) {
440 return $db;
441 }
442
443 $err = $db->connect();
444 if (PEAR::isError($err)) {
445 $dsn = $db->getDSN('string', 'xxx');
446 $db->disconnect();
447 $err->addUserInfo($dsn);
448 return $err;
449 }
450
451 return $db;
452 }
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
& factory($dsn, $options=false)
Create a new MDB2 object for the specified database type.
Definition: MDB2.php:379
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280

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

Referenced by ilDB\connectHost(), ilDB\doConnect(), ilDBMySQL\doConnect(), and ilDBOracle\doConnect().

+ 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 697 of file MDB2.php.

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

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\__construct().

+ 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 379 of file MDB2.php.

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

References $debug, $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 926 of file MDB2.php.

927 {
928 // safe_mode does notwork with is_readable()
929 if (!@ini_get('safe_mode')) {
930 $dirs = explode(PATH_SEPARATOR, ini_get('include_path'));
931 foreach ($dirs as $dir) {
932 if (@is_readable($dir . DIRECTORY_SEPARATOR . $file)) {
933 return true;
934 }
935 }
936 } else {
937 $fp = @fopen($file, 'r', true);
938 if (is_resource($fp)) {
939 @fclose($fp);
940 return true;
941 }
942 }
943 return false;
944 }
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $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 626 of file MDB2.php.

627 {
628 return is_a($value, 'MDB2_Driver_Common');
629 }

◆ 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 599 of file MDB2.php.

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

References $code, and $data.

Referenced by ilClient\checkDatabaseExists(), ilDB\connect(), ilDB\connectHost(), MDB2_Result_Common\execute(), ilDBOracle\getDBVersion(), ilDB\getLastInsertId(), ilDB\getOne(), ilDB\handleError(), ilDB\isDbError(), ilDB\listSequences(), ilDB\listTables(), 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 643 of file MDB2.php.

644 {
645 return is_a($value, 'MDB2_Result');
646 }

◆ 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 660 of file MDB2.php.

661 {
662 return is_a($value, 'MDB2_Result_Common');
663 }

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(), ilDBPdoReversePostgres\tableInfo(), 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 677 of file MDB2.php.

678 {
679 return is_a($value, 'MDB2_Statement');
680 }

◆ 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 330 of file MDB2.php.

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

References $debug, 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 521 of file MDB2.php.

522 {
523 $file_name = 'MDB2'.DIRECTORY_SEPARATOR.$file.'.php';
524 if (!MDB2::fileExists($file_name)) {
525 return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
526 'unable to find: '.$file_name);
527 }
528 if (!include_once($file_name)) {
529 return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
530 'unable to load driver class: '.$file_name);
531 }
532 return $file_name;
533 }

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

+ Here is the call graph for this function:

◆ parseDSN()

MDB2::parseDSN (   $dsn)

Definition at line 796 of file MDB2.php.

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

References $GLOBALS, and $key.

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 577 of file MDB2.php.

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

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 284 of file MDB2.php.

285 {
286 if (is_array($options)) {
287 foreach ($options as $option => $value) {
288 $test = $db->setOption($option, $value);
289 if (PEAR::isError($test)) {
290 return $test;
291 }
292 }
293 }
294 return MDB2_OK;
295 }
$test
Definition: Utf8Test.php:84

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 486 of file MDB2.php.

487 {
488 if ($dsn) {
489 $dsninfo = MDB2::parseDSN($dsn);
490 $dsninfo = array_merge($GLOBALS['_MDB2_dsninfo_default'], $dsninfo);
491 $keys = array_keys($GLOBALS['_MDB2_databases']);
492 for ($i=0, $j=count($keys); $i<$j; ++$i) {
493 if (isset($GLOBALS['_MDB2_databases'][$keys[$i]])) {
494 $tmp_dsn = $GLOBALS['_MDB2_databases'][$keys[$i]]->getDSN('array');
495 if (count(array_diff_assoc($tmp_dsn, $dsninfo)) == 0) {
496 MDB2::setOptions($GLOBALS['_MDB2_databases'][$keys[$i]], $options);
497 return $GLOBALS['_MDB2_databases'][$keys[$i]];
498 }
499 }
500 }
501 } elseif (is_array($GLOBALS['_MDB2_databases']) && reset($GLOBALS['_MDB2_databases'])) {
502 $db =& $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])];
503 return $db;
504 }
505 $db =& MDB2::factory($dsn, $options);
506 return $db;
507 }
$i
Definition: disco.tpl.php:19
$keys

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

+ Here is the call graph for this function:

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