PHP Класс 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.
Автор: Tyler Antonio, University of Alberta. ([email protected])
Показать файл Открыть проект

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
__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

Описание методов

applyPrefix() публичный Метод

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
Результат string Table with configured prefix

getInstance() публичный статический Метод

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
Результат Database The shared database connection.

getLastError() публичный Метод

Return an array with information about the last operation performed in the database.
public getLastError ( ) : array
Результат array The array with error information.

read() публичный Метод

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
Результат PDOStatement object

write() публичный Метод

This executes queries directly on the master.
public write ( string $stmt, array $params = [] ) : integer
$stmt string Prepared SQL statement
$params array Parameters
Результат integer The number of rows affected by the query.