PHP Class 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.
Inheritance: implements Airship\Engine\Contract\DBInterface
Afficher le fichier Open project: paragonie/airship Class Usage Examples

Protected Properties

Свойство Type Description
$dbengine string
$pdo PDO

Méthodes publiques

Méthode Description
__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.

Method Details

__construct() public méthode

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

beginTransaction() public méthode

Initiates a transaction
public beginTransaction ( ) : boolean
Résultat boolean

cell() public méthode

Variadic version of $this->single()
public cell ( string $statement, $params ) : mixed
$statement string SQL query without user data
$params Parameters
Résultat mixed

col() public méthode

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
Résultat mixed

column() public méthode

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?
Résultat mixed

commit() public méthode

Commits a transaction
public commit ( ) : boolean
Résultat boolean

delete() public méthode

Delete rows in a database table.
public delete ( string $table, array $conditions = [] ) : mixed
$table string - table name
$conditions array - WHERE clause
Résultat mixed

errorCode() public méthode

Fetch the SQLSTATE associated with the last operation on the database handle
public errorCode ( ) : string
Résultat string

errorInfo() public méthode

Fetch extended error information associated with the last operation on the database handle
public errorInfo ( ) : array
Résultat array

escapeIdentifier() public méthode

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`)
Résultat string

escapeValueSet() public méthode

Input: ([1, 2, 3, 5], int) Output: "(1,2,3,5)"
public escapeValueSet ( array $values, string $type = 'string' ) : string
$values array
$type string
Résultat string

exec() public méthode

Execute an SQL statement and return the number of affected rows
public exec ( string $statement ) : integer
$statement string
Résultat integer

exists() public méthode

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
Résultat boolean

factory() public static méthode

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
Résultat Database

first() public méthode

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
Résultat mixed

flattenDSN() public static méthode

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
Résultat array [$dsn, $driver]

getAttribute() public méthode

Retrieve a database connection attribute
public getAttribute ( integer $attr ) : mixed
$attr integer
Résultat mixed

getAvailableDrivers() public méthode

Return an array of available PDO drivers
public getAvailableDrivers ( ) : array
Résultat array

getDriver() public méthode

Which database driver are we operating on?
public getDriver ( ) : string
Résultat string

getPdo() public méthode

Return the PDO object directly
public getPdo ( ) : PDO
Résultat PDO

inTransaction() public méthode

Checks if inside a transaction
public inTransaction ( ) : boolean
Résultat boolean

insert() public méthode

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
Résultat mixed

insertGet() public méthode

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
Résultat mixed

insertMany() public méthode

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
Résultat boolean

lastInsertId() public méthode

Returns the ID of the last inserted row or sequence value
public lastInsertId ( $args ) : string
$args
Résultat string

prepare() public méthode

Prepares a statement for execution and returns a statement object
public prepare ( $args ) : PDOStatement | boolean
$args
Résultat PDOStatement | boolean

query() public méthode

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
Résultat PDOStatement | boolean

quote() public méthode

Quotes a string for use in a query
public quote ( $args ) : string
$args
Résultat string

rollBack() public méthode

Rolls back a transaction
public rollBack ( ) : boolean
Résultat boolean

row() public méthode

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
Résultat mixed

run() public méthode

PHP 5.6 variadic shorthand for $this->safeQuery()
public run ( string $statement, $params ) : mixed
$statement string SQL query without user data
$params Parameters
Résultat mixed - If successful, a 2D array

safeQuery() public méthode

Perform a Parameterized Query
public safeQuery ( string $statement, array $params = [], integer $fetch_style = PDO::FETCH_ASSOC ) : mixed
$statement string
$params array
$fetch_style integer
Résultat mixed -- array if SELECT

setAttribute() public méthode

Set an attribute
public setAttribute ( $args ) : boolean
$args
Résultat boolean

single() public méthode

Fetch a single result -- useful for SELECT COUNT() queries
public single ( string $statement, array $params = [] ) : mixed
$statement string
$params array
Résultat mixed

update() public méthode

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
Résultat mixed

Property Details

$dbengine protected_oe property

protected string $dbengine
Résultat string

$pdo protected_oe property

protected PDO $pdo
Résultat PDO