Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
MySQL Class Reference

Caches data to a MySQL database. More...

Inheritance diagram for MySQL:
DB

Public Member Functions

 __construct ($location, $name, $type)
 Create a new cache object.
 
 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.
 
 load ()
 Retrieve the data saved to the cache.
 
 mtime ()
 Retrieve the last modified time for the cache.
 
 parseDSN ($dsn)
 
 save ($data)
 Save data to the cache.
 
 touch ()
 Set the last modified time to the current time.
 
 unlink ()
 Remove the cache.
 

Static Protected Member Functions

static prepare_simplepie_object_for_cache ($data)
 Helper for database conversion.
 

Protected Attributes

string $id
 Cache ID.
 
PDO $mysql
 PDO instance.
 
array $options
 Options.
 

Detailed Description

Caches data to a MySQL database.

Registered for URLs with the "mysql" protocol

For example, mysql://root:password@localhost:3306/mydb?prefix=sp_ will connect to the mydb database on localhost on port 3306, with the user root and the password password. All tables will be prefixed with sp_

@subpackage Caching

Deprecated
since SimplePie 1.8.0, use implementation of "Psr::SimpleCache::CacheInterface" instead

Constructor & Destructor Documentation

◆ __construct()

MySQL::__construct ( $location,
$name,
$type )

Create a new cache object.

Parameters
string$locationLocation string (from SimplePie\$cache_location)
string$nameUnique ID for the cache
Base\TYPE_FEED | Base\TYPE_IMAGE$typeEither TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data

Member Function Documentation

◆ apiVersion()

DB::apiVersion ( )
inherited

Return the DB API version.

Return values
intthe DB API version number

◆ assertExtension()

DB::assertExtension ( $name)
inherited

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 )
inherited

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)
inherited

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)
inherited

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)
inherited

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

◆ load()

MySQL::load ( )

Retrieve the data saved to the cache.

Return values
arrayData for SimplePie\$data

◆ mtime()

MySQL::mtime ( )

Retrieve the last modified time for the cache.

Return values
intTimestamp

◆ prepare_simplepie_object_for_cache()

static DB::prepare_simplepie_object_for_cache ( $data)
staticprotectedinherited

Helper for database conversion.

Converts a given {

See also
SimplePie} object into data to be stored
Parameters
SimplePie\SimplePie$data
Return values
arrayFirst item is the serialized data for storage, second item is the unique ID for this item

◆ save()

MySQL::save ( $data)

Save data to the cache.

Parameters
array | SimplePie\SimplePie$dataData to store in the cache. If passed a SimplePie object, only cache the $data property
Return values
boolSuccessfulness

◆ touch()

MySQL::touch ( )

Set the last modified time to the current time.

Return values
boolSuccess status

◆ unlink()

MySQL::unlink ( )

Remove the cache.

Return values
boolSuccess status

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