Moodle PHP Documentation 4.1
Moodle 4.1.11 (Build: 20240610) (c8c84b4af18)
DB Class Reference

The main "DB" class is simply a container class with some static methods for creating DB objects as well as some utility functions common to all parts of DB. More...

Public Member Functions

 apiVersion ()
 Return the DB API version.
 
 assertExtension ($name)
 Load a PHP database extension if it is not loaded already.
 
 connect ($dsn, $options=false)
 Create a new DB object and connect to the specified database.
 
 factory ($type)
 Create a new DB object for the specified database type.
 
 isError ($value)
 Tell whether a result code from a DB method is an error.
 
 isWarning ($value)
 Tell whether a result code from a DB method is a warning.
 
 parseDSN ($dsn)
 

Detailed Description

The main "DB" class is simply a container class with some static methods for creating DB objects as well as some utility functions common to all parts of DB.

Member Function Documentation

◆ apiVersion()

DB::apiVersion ( )

Return the DB API version.

Return values
intthe DB API version number

◆ assertExtension()

DB::assertExtension ( $name)

Load a PHP database extension if it is not loaded already.

Parameters
$namethe base name of the extension (without the .so or .dll suffix)
Return values
booltrue if the extension was already or successfully loaded, false if it could not be loaded

◆ connect()

DB::connect ( $dsn,
$options = false )

Create a new DB object and connect to the specified database.

Parameters
$dsnmixed "data source name", see the DB\parseDSN method for a description of the dsn format. Can also be specified as an array of the format returned by DB\parseDSN.
$optionsmixed if boolean (or scalar), tells whether this connection should be persistent (for backends that support this). This parameter can also be an array of options, see DB_common\setOption for more information on connection options.
Return values
objecta newly created DB connection object, or a DB error object on error
See also
DB\parseDSN
DB\isError

◆ factory()

DB::factory ( $type)

Create a new DB object for the specified database type.

Parameters
$typestring database type, for example "mysql"
Return values
objecta newly created DB object, or a DB error code on error

◆ isError()

DB::isError ( $value)

Tell whether a result code from a DB method is an error.

Parameters
$valueint result code
Return values
boolwhether $value is an error

◆ isWarning()

DB::isWarning ( $value)

Tell whether a result code from a DB method is a warning.

Warnings differ from errors in that they are generated by DB, and are not fatal.

Parameters
$valuemixed result value
Return values
boolwhether $value is a warning

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