PHP Class ParagonIE\EasyDB\EasyDB

Afficher le fichier Open project: paragonie/easydb Class Usage Examples

Protected Properties

Свойство Type Description
$allowSeparators boolean
$dbEngine string
$pdo PDO

Méthodes publiques

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

Method Details

__construct() public méthode

Dependency-Injectable constructor
public __construct ( PDO $pdo, 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 ) : integer
$table string - table name
$conditions array - WHERE clause
Résultat integer

errorCode() public méthode

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

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

escapeLikeValue() public méthode

Input: ("string_not%escaped") Output: "string\_not\%escaped" WARNING: This function always escapes wildcards using backslash!
public escapeLikeValue ( string $value ) : string
$value string
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 ( $args ) : integer
$args
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
$params
Résultat boolean

first() public méthode

Get the first column of each row
public first ( string $statement, $params ) : mixed
$statement string
$params
Résultat mixed

getAttribute() public méthode

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

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
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 ) : integer
$table string - table name
$maps array - array of associative array specifying values should be assigned to each field
Résultat integer

is1DArray() public méthode

Make sure none of this array's elements are arrays
public is1DArray ( array $params ) : boolean
$params array
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
$args
Résultat PDOStatement

q() public méthode

Variadic shorthand for $this->safeQuery()
public q ( string $statement, $params ) : mixed
$statement string SQL query without user data
$params Parameters
Résultat mixed

query() public méthode

Executes an SQL statement, returning a result set as a PDOStatement object
public query ( $args ) : PDOStatement
$args
Résultat PDOStatement

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->q() 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

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

setAllowSeparators() public méthode

public setAllowSeparators ( boolean $value ) : self
$value boolean
Résultat self

setAttribute() public méthode

Set an attribute
public setAttribute ( integer $attr, mixed $value ) : boolean
$attr integer
$value mixed
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 ) : integer
$table string Table name
$changes array Associative array of which values should be assigned to each field
$conditions array WHERE clause
Résultat integer

Property Details

$allowSeparators protected_oe property

protected bool $allowSeparators
Résultat boolean

$dbEngine protected_oe property

protected string $dbEngine
Résultat string

$pdo protected_oe property

protected PDO $pdo
Résultat PDO