PHP Класс ParagonIE\EasyDB\EasyDB

Показать файл Открыть проект Примеры использования класса

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

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

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

Метод Описание
__construct ( PDO $pdo, 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 ) : integer Delete rows in a database table.
errorCode ( ) : mixed 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
escapeLikeValue ( string $value ) : string Escape a value that will be used as a LIKE condition.
escapeValueSet ( array $values, string $type = 'string' ) : string Create a parenthetical statement e.g. for NOT IN queries.
exec ( $args ) : 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.
first ( string $statement, $params ) : mixed Get the first column of each row
getAttribute ( $args ) : 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 a copy of the PDO object (to prevent it from being modified to disable safety/security features).
inTransaction ( ) : boolean Checks if inside a transaction
insert ( string $table, array $map ) : integer 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 ) : integer Insert many new rows to a table in a database. using the same prepared statement
is1DArray ( array $params ) : boolean Make sure none of this array's elements are arrays
lastInsertId ( $args ) : string Returns the ID of the last inserted row or sequence value
prepare ( $args ) : PDOStatement Prepares a statement for execution and returns a statement object
q ( string $statement, $params ) : mixed Variadic shorthand for $this->safeQuery()
query ( $args ) : PDOStatement 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->q() except it only returns a single row
run ( string $statement, $params ) : mixed Variadic shorthand for $this->safeQuery()
safeQuery ( string $statement, array $params = [], integer $fetchStyle = PDO::FETCH_ASSOC, boolean $returnNumAffected = false ) : array | integer Perform a Parametrized Query
setAllowSeparators ( boolean $value ) : self
setAttribute ( integer $attr, mixed $value ) : 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 ) : integer Update a row in a database table.

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

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

Dependency-Injectable constructor
public __construct ( PDO $pdo, 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 ) : integer
$table string - table name
$conditions array - WHERE clause
Результат integer

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

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

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

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

Input: ("string_not%escaped") Output: "string\_not\%escaped" WARNING: This function always escapes wildcards using backslash!
public escapeLikeValue ( string $value ) : string
$value string
Результат 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 ( $args ) : integer
$args
Результат integer

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

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

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

Get the first column of each row
public first ( string $statement, $params ) : mixed
$statement string
$params
Результат mixed

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

Retrieve a database connection attribute
public getAttribute ( $args ) : mixed
$args
Результат 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 a copy of the PDO object (to prevent it from being modified to disable safety/security features).
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 ) : integer
$table string - table name
$map array - associative array of which values should be assigned to each field
Результат integer

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
Результат mixed

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

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

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

Make sure none of this array's elements are arrays
public is1DArray ( array $params ) : boolean
$params array
Результат 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
$args
Результат PDOStatement

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

Variadic shorthand for $this->safeQuery()
public q ( string $statement, $params ) : mixed
$statement string SQL query without user data
$params Parameters
Результат mixed

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

Executes an SQL statement, returning a result set as a PDOStatement object
public query ( $args ) : PDOStatement
$args
Результат PDOStatement

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->q() except it only returns a single row
public row ( string $statement, $params ) : mixed
$statement string SQL query without user data
$params Parameters
Результат mixed

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

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 Parametrized Query
public safeQuery ( string $statement, array $params = [], integer $fetchStyle = PDO::FETCH_ASSOC, boolean $returnNumAffected = false ) : array | integer
$statement string The query string (hopefully untainted by user input)
$params array The parameters (used in prepared statements)
$fetchStyle integer PDO::FETCH_STYLE
$returnNumAffected boolean Return the number of rows affected?
Результат array | integer

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

public setAllowSeparators ( boolean $value ) : self
$value boolean
Результат self

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

Set an attribute
public setAttribute ( integer $attr, mixed $value ) : boolean
$attr integer
$value mixed
Результат 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 ) : integer
$table string Table name
$changes array Associative array of which values should be assigned to each field
$conditions array WHERE clause
Результат integer

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

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

protected bool $allowSeparators
Результат boolean

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

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

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

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