PHP Class SimpleSAML\Database

This database class supports a single database, or a master/slave configuration with as many defined slaves as a user would like. The goal of this class is to provide a single mechanism to connect to a database that can be reused by any component within SimpleSAMLphp including modules. When using this class, the global configuration should be passed here, but in the case of a module that has a good reason to use a different database, such as sqlauth, an alternative config file can be provided.
Author: Tyler Antonio, University of Alberta. ([email protected])
Afficher le fichier Open project: simplesamlphp/simplesamlphp

Méthodes publiques

Méthode Description
applyPrefix ( string $table ) : string This function simply applies the table prefix to a supplied table name.
getInstance ( SimpleSAML_Configuration $altConfig = null ) : Database Retrieves the current database instance. Will create a new one if there isn't an existing connection.
getLastError ( ) : array Return an array with information about the last operation performed in the database.
read ( string $stmt, array $params = [] ) : PDOStatement This executes queries on a database server that is determined by this::getSlave().
write ( string $stmt, array $params = [] ) : integer This executes queries directly on the master.

Private Methods

Méthode Description
__construct ( SimpleSAML_Configuration $config ) Private constructor that restricts instantiation to getInstance().
connect ( string $dsn, string $username, string $password, array $options ) : PDO This function connects to a database.
exec ( PDO $db, string $stmt ) : integer This function queries the database without using a prepared statement.
generateInstanceId ( SimpleSAML_Configuration $config ) : string Generate an Instance ID based on the database configuration.
getSlave ( ) : PDO This function randomly selects a slave database server to query. In the event no slaves are configured, it will return the master.
query ( PDO $db, string $stmt, array $params ) : PDOStatement This function queries the database

Method Details

applyPrefix() public méthode

This function simply applies the table prefix to a supplied table name.
public applyPrefix ( string $table ) : string
$table string Table to apply prefix to, if configured
Résultat string Table with configured prefix

getInstance() public static méthode

Retrieves the current database instance. Will create a new one if there isn't an existing connection.
public static getInstance ( SimpleSAML_Configuration $altConfig = null ) : Database
$altConfig SimpleSAML_Configuration Optional: Instance of a SimpleSAML_Configuration class
Résultat Database The shared database connection.

getLastError() public méthode

Return an array with information about the last operation performed in the database.
public getLastError ( ) : array
Résultat array The array with error information.

read() public méthode

This executes queries on a database server that is determined by this::getSlave().
public read ( string $stmt, array $params = [] ) : PDOStatement
$stmt string Prepared SQL statement
$params array Parameters
Résultat PDOStatement object

write() public méthode

This executes queries directly on the master.
public write ( string $stmt, array $params = [] ) : integer
$stmt string Prepared SQL statement
$params array Parameters
Résultat integer The number of rows affected by the query.