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
파일 보기 프로젝트 열기: paragonie/airship 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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