PHP Класс PDOWrapper

Автор: xuanyan ([email protected])
Наследование: extends DatabaseAbstract, implements DatabaseWrapper
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$LOG_ERRORS boolean Write all errors to error log
$TIMESTAMP_WRITES boolean Automatically add/update created/updated fields

Защищенные свойства (Protected)

Свойство Тип Описание
$config_master Dynamic master config creds
$config_slaves Dynamic slave config creds
$instance PDOWrapper A reference to the singleton instance
$pdo_exception We will cache any PDO errors in case we want to get out them externally
$pdo_master The PDO objects for the master connection
$pdo_slave The PDO objects for the slave connection

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

Метод Описание
__destruct ( ) Destructor.
configMaster ( $host, $name, $user, $password, $port = null, $driver = 'mysql' ) method configMaster - configure connection credentials to the master db server
configSlave ( $host, $name, $user, $password, $port = null, $driver = 'mysql' ) method configSlave - configure a connection to a slave (can be called multiple times)
delete ( $table, $params = [] ) : boolean method delete.
execute ( string $query, $params = [] ) : mixed method execute.
getErrorMessage ( ) method getErrorMessage.
getPDOException ( ) method getError.
insert ( string $table, array $params = [], boolean $timestamp_this = null ) : mixed method insert.
insertMultiple ( string $table, array $columns = [], $rows = [], boolean $timestamp_these = null ) : mixed method insertMultiple.
instance ( ) : - method instance.
query ( string $query, array $params = [], boolean $use_master = false ) : mixed method query.
queryFirst ( string $query, array $params = [], boolean $use_master = false ) : mixed method queryFirst.
select ( string $table, array $params = null, integer $limit = null, integer $start = null, array $order_by = null, boolean $use_master = false ) : mixed method select.
selectFirst ( $table, $params = [], array $order_by = null ) : mixed method selectFirst.
selectFirstMaster ( $table, $params = [], array $order_by = null ) : mixed method selectFirstMaster.
selectMaster ( $table, $params = [], integer $limit = null, integer $start = null, array $order_by = null ) : mixed method selectMaster.
update ( string $table, array $params, array $wheres = [], boolean $timestamp_this = null ) : integer | boolean method update.

Защищенные методы

Метод Описание
__construct ( ) Constructor.
createConnection ( $driver, $host, $name, $user, $password, $port = null ) : PDO method createConnection.
getMaster ( ) method getMaster.
getSlave ( ) method getSlave.

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

Метод Описание
validateDriver ( string $driver ) : boolean Validate the database in question is supported by your installation of PHP.

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

__construct() защищенный Метод

- make protected so only subclasses and self can create this object (singleton)
protected __construct ( )

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

- release the PDO db connections
public __destruct ( )

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

method configMaster - configure connection credentials to the master db server
public configMaster ( $host, $name, $user, $password, $port = null, $driver = 'mysql' )

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

method configSlave - configure a connection to a slave (can be called multiple times)
public configSlave ( $host, $name, $user, $password, $port = null, $driver = 'mysql' )

createConnection() защищенный Метод

- create a PDO connection using the credentials provided
protected createConnection ( $driver, $host, $name, $user, $password, $port = null ) : PDO
Результат PDO object with a connection to the database specified

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

- deletes rows from a table based on the parameters
public delete ( $table, $params = [] ) : boolean
Результат boolean - associate representing the fetched table row, false on failure

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

- executes a query that modifies the database
public execute ( string $query, $params = [] ) : mixed
$query string - the SQL query we are executing
Результат mixed - the affected rows, false on failure

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

- returns the last error message caught
public getErrorMessage ( )

getMaster() защищенный Метод

- grab the PDO connection to the master DB
protected getMaster ( )

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

- returns the actual PDO exception
public getPDOException ( )

getSlave() защищенный Метод

- grab the PDO connection to the slave DB, create it if not there
protected getSlave ( )

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

- adds a row to the specified table
public insert ( string $table, array $params = [], boolean $timestamp_this = null ) : mixed
$table string - the name of the db table we are adding row to
$params array - associative array representing the columns and their respective values
$timestamp_this boolean (Optional), if true we set date_created and date_modified values to now
Результат mixed - new primary key of inserted table, false on failure

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

- adds multiple rows to a table with a single query
public insertMultiple ( string $table, array $columns = [], $rows = [], boolean $timestamp_these = null ) : mixed
$table string - the name of the db table we are adding row to
$columns array - contains the column names
$timestamp_these boolean (Optional), if true we set date_created and date_modified values to NOW() for each row
Результат mixed - new primary key of inserted table, false on failure

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

- static, for singleton, for creating a global instance of this object
public static instance ( ) : -
Результат -

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

- returns data from a free form select query
public query ( string $query, array $params = [], boolean $use_master = false ) : mixed
$query string - the SQL query we are executing
$params array - a list of bind parameters
$use_master boolean (Optional) - whether or not to use the master connection
Результат mixed - the affected rows, false on failure

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

- returns the first record from a free form select query
public queryFirst ( string $query, array $params = [], boolean $use_master = false ) : mixed
$query string - the SQL query we are executing
$params array - a list of bind parameters
$use_master boolean (Optional) - whether or not to use the master connection
Результат mixed - the affected rows, false on failure

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

- retrieve information from the database, as an array
public select ( string $table, array $params = null, integer $limit = null, integer $start = null, array $order_by = null, boolean $use_master = false ) : mixed
$table string - the name of the db table we are retreiving the rows from
$params array - associative array representing the WHERE clause filters
$limit integer (optional) - the amount of rows to return
$start integer (optional) - the row to start on, indexed by zero
$order_by array (optional) - an array with order by clause
$use_master boolean (optional) - use the master db for this read
Результат mixed - associate representing the fetched table row, false on failure

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

- retrieve the first row returned from a select statement
public selectFirst ( $table, $params = [], array $order_by = null ) : mixed
$order_by array (optional) - an array with order by clause
Результат mixed - associate representing the fetched table row, false on failure

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

- retrieve the first row returned from a select statement using the master database
public selectFirstMaster ( $table, $params = [], array $order_by = null ) : mixed
$order_by array (optional) - an array with order by clause
Результат mixed - associate representing the fetched table row, false on failure

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

- retrieve information from the master database, as an array
public selectMaster ( $table, $params = [], integer $limit = null, integer $start = null, array $order_by = null ) : mixed
$limit integer (optional) - the amount of rows to return
$start integer (optional) - the row to start on, indexed by zero
$order_by array (optional) - an array with order by clause
Результат mixed - associate representing the fetched table row, false on failure

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

- updates a row to the specified table
public update ( string $table, array $params, array $wheres = [], boolean $timestamp_this = null ) : integer | boolean
$table string - the name of the db table we are adding row to
$params array - associative array representing the columns and their respective values to update
$wheres array (Optional) - the where clause of the query
$timestamp_this boolean (Optional) - if true we set date_created and date_modified values to now
Результат integer | boolean - the amount of rows updated, false on failure

Описание свойств

$LOG_ERRORS публичное статическое свойство

Write all errors to error log
public static bool $LOG_ERRORS
Результат boolean

$TIMESTAMP_WRITES публичное статическое свойство

Automatically add/update created/updated fields
public static bool $TIMESTAMP_WRITES
Результат boolean

$config_master защищенное свойство

Dynamic master config creds
protected $config_master

$config_slaves защищенное свойство

Dynamic slave config creds
protected $config_slaves

$instance защищенное статическое свойство

A reference to the singleton instance
protected static PDOWrapper $instance
Результат PDOWrapper

$pdo_exception защищенное свойство

We will cache any PDO errors in case we want to get out them externally
protected $pdo_exception

$pdo_master защищенное свойство

The PDO objects for the master connection
protected $pdo_master

$pdo_slave защищенное свойство

The PDO objects for the slave connection
protected $pdo_slave