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])
파일 보기 프로젝트 열기: simplesamlphp/simplesamlphp

공개 메소드들

메소드 설명
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.