PHP Класс Airship\Engine\Database

Wraps PDO and gives a bunch of nice and easy one-liners that in most cases use Prepared Statements to ensure we aren't committing a huge security foot-cannon.
Наследование: implements Airship\Engine\Contract\DBInterface
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$dbengine string
$pdo PDO

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

Метод Описание
__construct ( PDO $pdo = null, string $dbEngine = '' ) Dependency-Injectable constructor
beginTransaction ( ) : boolean Initiates a transaction
cell ( string $statement, $params ) : mixed Variadic version of $this->single()
col ( string $statement, integer $offset, $params ) : mixed Variadic version of $this->column()
column ( string $statement, array $params = [], integer $offset ) : mixed Fetch a column
commit ( ) : boolean Commits a transaction
delete ( string $table, array $conditions = [] ) : mixed Delete rows in a database table.
errorCode ( ) : string Fetch the SQLSTATE associated with the last operation on the database handle
errorInfo ( ) : array Fetch extended error information associated with the last operation on the database handle
escapeIdentifier ( string $string, boolean $quote = true ) : string Make sure only valid characters make it in column/table names
escapeValueSet ( array $values, string $type = 'string' ) : string Create a parenthetical statement e.g. for NOT IN queries.
exec ( string $statement ) : integer Execute an SQL statement and return the number of affected rows
exists ( string $statement, $params ) : boolean Use with SELECT COUNT queries to determine if a record exists.
factory ( string $dsn, string $username = '', string $password = '', array $options = [] ) : Database Create a new Database object based on PDO constructors
first ( string $statement, $params ) : mixed Variadic version of $this->column(), with an offset of 0
flattenDSN ( array $dbConf, string $username = '', string $password = '' ) : array Flatten an array into a DSN string and driver
getAttribute ( integer $attr ) : mixed Retrieve a database connection attribute
getAvailableDrivers ( ) : array Return an array of available PDO drivers
getDriver ( ) : string Which database driver are we operating on?
getPdo ( ) : PDO Return the PDO object directly
inTransaction ( ) : boolean Checks if inside a transaction
insert ( string $table, array $map = [] ) : mixed Insert a new row to a table in a database.
insertGet ( string $table, array $map, string $field ) : mixed Insert a new record then get a particular field from the new row
insertMany ( string $table, array $maps ) : boolean Insert many new rows to a table in a database. using the same prepared statement
lastInsertId ( $args ) : string Returns the ID of the last inserted row or sequence value
prepare ( $args ) : PDOStatement | boolean Prepares a statement for execution and returns a statement object
query ( string $statement, integer $mode = PDO::ATTR_DEFAULT_FETCH_MODE, mixed $arg3 = null ) : PDOStatement | boolean Executes an SQL statement, returning a result set as a PDOStatement object
quote ( $args ) : string Quotes a string for use in a query
rollBack ( ) : boolean Rolls back a transaction
row ( string $statement, $params ) : mixed Similar to $this->row() except it only returns a single row
run ( string $statement, $params ) : mixed PHP 5.6 variadic shorthand for $this->safeQuery()
safeQuery ( string $statement, array $params = [], integer $fetch_style = PDO::FETCH_ASSOC ) : mixed Perform a Parameterized Query
setAttribute ( $args ) : boolean Set an attribute
single ( string $statement, array $params = [] ) : mixed Fetch a single result -- useful for SELECT COUNT() queries
update ( string $table, array $changes, array $conditions ) : mixed Update a row in a database table.

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

__construct() публичный метод

Dependency-Injectable constructor
public __construct ( PDO $pdo = null, string $dbEngine = '' )
$pdo PDO
$dbEngine string

beginTransaction() публичный метод

Initiates a transaction
public beginTransaction ( ) : boolean
Результат boolean

cell() публичный метод

Variadic version of $this->single()
public cell ( string $statement, $params ) : mixed
$statement string SQL query without user data
$params Parameters
Результат mixed

col() публичный метод

Variadic version of $this->column()
public col ( string $statement, integer $offset, $params ) : mixed
$statement string SQL query without user data
$offset integer - How many columns from the left are we grabbing from each row?
$params Parameters
Результат mixed

column() публичный метод

Fetch a column
public column ( string $statement, array $params = [], integer $offset ) : mixed
$statement string SQL query without user data
$params array Parameters
$offset integer - How many columns from the left are we grabbing from each row?
Результат mixed

commit() публичный метод

Commits a transaction
public commit ( ) : boolean
Результат boolean

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

Delete rows in a database table.
public delete ( string $table, array $conditions = [] ) : mixed
$table string - table name
$conditions array - WHERE clause
Результат mixed

errorCode() публичный метод

Fetch the SQLSTATE associated with the last operation on the database handle
public errorCode ( ) : string
Результат string

errorInfo() публичный метод

Fetch extended error information associated with the last operation on the database handle
public errorInfo ( ) : array
Результат array

escapeIdentifier() публичный метод

Make sure only valid characters make it in column/table names
public escapeIdentifier ( string $string, boolean $quote = true ) : string
$string string - table or column name
$quote boolean - certain SQLs escape column names (i.e. mysql with `backticks`)
Результат string

escapeValueSet() публичный метод

Input: ([1, 2, 3, 5], int) Output: "(1,2,3,5)"
public escapeValueSet ( array $values, string $type = 'string' ) : string
$values array
$type string
Результат string

exec() публичный метод

Execute an SQL statement and return the number of affected rows
public exec ( string $statement ) : integer
$statement string
Результат integer

exists() публичный метод

Use with SELECT COUNT queries to determine if a record exists.
public exists ( string $statement, $params ) : boolean
$statement string SQL query without user data
$params Parameters
Результат boolean

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

Create a new Database object based on PDO constructors
public static factory ( string $dsn, string $username = '', string $password = '', array $options = [] ) : Database
$dsn string
$username string
$password string
$options array
Результат Database

first() публичный метод

Variadic version of $this->column(), with an offset of 0
public first ( string $statement, $params ) : mixed
$statement string SQL query without user data
$params Parameters
Результат mixed

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

Flatten an array into a DSN string and driver
public static flattenDSN ( array $dbConf, string $username = '', string $password = '' ) : array
$dbConf array
$username string
$password string
Результат array [$dsn, $driver]

getAttribute() публичный метод

Retrieve a database connection attribute
public getAttribute ( integer $attr ) : mixed
$attr integer
Результат mixed

getAvailableDrivers() публичный метод

Return an array of available PDO drivers
public getAvailableDrivers ( ) : array
Результат array

getDriver() публичный метод

Which database driver are we operating on?
public getDriver ( ) : string
Результат string

getPdo() публичный метод

Return the PDO object directly
public getPdo ( ) : PDO
Результат PDO

inTransaction() публичный метод

Checks if inside a transaction
public inTransaction ( ) : boolean
Результат boolean

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

Insert a new row to a table in a database.
public insert ( string $table, array $map = [] ) : mixed
$table string - table name
$map array - associative array of which values should be assigned to each field
Результат mixed

insertGet() публичный метод

Insert a new record then get a particular field from the new row
public insertGet ( string $table, array $map, string $field ) : mixed
$table string
$map array
$field string The field name to return of the new entry
Результат mixed

insertMany() публичный метод

Insert many new rows to a table in a database. using the same prepared statement
public insertMany ( string $table, array $maps ) : boolean
$table string - table name
$maps array - array of associative array specifying values should be assigned to each field
Результат boolean

lastInsertId() публичный метод

Returns the ID of the last inserted row or sequence value
public lastInsertId ( $args ) : string
$args
Результат string

prepare() публичный метод

Prepares a statement for execution and returns a statement object
public prepare ( $args ) : PDOStatement | boolean
$args
Результат PDOStatement | boolean

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

Executes an SQL statement, returning a result set as a PDOStatement object
public query ( string $statement, integer $mode = PDO::ATTR_DEFAULT_FETCH_MODE, mixed $arg3 = null ) : PDOStatement | boolean
$statement string
$mode integer
$arg3 mixed
Результат PDOStatement | boolean

quote() публичный метод

Quotes a string for use in a query
public quote ( $args ) : string
$args
Результат string

rollBack() публичный метод

Rolls back a transaction
public rollBack ( ) : boolean
Результат boolean

row() публичный метод

Similar to $this->row() except it only returns a single row
public row ( string $statement, $params ) : mixed
$statement string SQL query without user data
$params Parameters
Результат mixed

run() публичный метод

PHP 5.6 variadic shorthand for $this->safeQuery()
public run ( string $statement, $params ) : mixed
$statement string SQL query without user data
$params Parameters
Результат mixed - If successful, a 2D array

safeQuery() публичный метод

Perform a Parameterized Query
public safeQuery ( string $statement, array $params = [], integer $fetch_style = PDO::FETCH_ASSOC ) : mixed
$statement string
$params array
$fetch_style integer
Результат mixed -- array if SELECT

setAttribute() публичный метод

Set an attribute
public setAttribute ( $args ) : boolean
$args
Результат boolean

single() публичный метод

Fetch a single result -- useful for SELECT COUNT() queries
public single ( string $statement, array $params = [] ) : mixed
$statement string
$params array
Результат mixed

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

Update a row in a database table.
public update ( string $table, array $changes, array $conditions ) : mixed
$table string - table name
$changes array - associative array of which values should be assigned to each field
$conditions array - WHERE clause
Результат mixed

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

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

protected string $dbengine
Результат string

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

protected PDO $pdo
Результат PDO