Download the PHP package vertilia/pdo-wrap without Composer
On this page you can find all versions of the php package vertilia/pdo-wrap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package pdo-wrap
pdo-wrap - PDO wrapper library to simplify basic DB operations
PDO (PHP Data Objects) is a standard interface to work with databases from PHP applications. Although it provides a full set of DB-related features for large list of providers, some basic operations seem to lack simplicity.
This package adds some form of simplicity and elegance to your work with PDO-based DB connections from PHP code.
It features:
- typed placeholders without sacrificing standard placeholders form, recognized by most IDEs,
- transparent typed parameter binding allowing simple chaining operations.
Example
Quick example for fetching a record set of several rows with inbound named parameter with PDO:
Yes, there is no standard PDO way of having automatic array unfolding when specifying lists...
Compare the same operation with PdoWrap
:
Two main
PdoWrap
concepts implemented in one example. First, we provided type information by appending[i]
suffix to the name in the list of parameters. Second,:acls
named parameter was unfurled to include several elements from array, since the[i]
suffix indicates that corresponding value must be represented as a list of integers.Also note:
:acls
placeholder is in the standard PDO form of named parameters, it will be automatically recognized by IDEs as such.
See below for the full list of available types.
Types reference
PdoWrap
extends PDO class and adds 3 helper methods that you will use on daily basis:
queryFetchAll()
\ to execute SELECT statements with typed placeholders and return the whole recordset (same as normal sequencePDO::prepare
/PDOStatement::bindValue
× n /PDOStatement::execute
/PDOStatement::fetchAll
),queryFetchOne()
\ to execute SELECT statements with typed placeholders and return the first record (same as normal sequencePDO::prepare
/PDOStatement::bindValue
× n /PDOStatement::execute
/PDOStatement::fetch
/PDOStatement::closeCursor
),queryExecute()
\ to execute DML statements with typed placeholders (same as normal sequencePDO::prepare
/PDOStatement::bindValue
× n /PDOStatement::execute
/PDOStatement::rowCount
).
All these methods receive as their first argument an SQL statement with either question-mark placeholders (as in ?
) or
named placeholders (as in :name
). Second argument is an array with values to use for corresponding placeholders.
Additional arguments representing PDO fetch modes may follow, they will be transmitted to corresponding
PDOStatement::fetchAll()
or PDOStatement::fetch()
methods.
For question-mark placeholders typing can not be provided, so the values are stored in a numeric array, exactly like in
standard PDO form PDO::prepare()->execute()
. This form is kept for compatibility.
For named placeholders, values are passed in associative array, where keys correspond to the name of placeholder in SQL
statement, but have type indicator suffix, like in :acls[i]
.
Type indicator is a suffix appended to parameter name in the list of parameters passed to corresponding query*()
method, and it may be in one of two forms, either in angle brackets (like <TYPE>
), to specify a single value of
specified type, or in square brackets (like [TYPE]
), to specify an array of values of specified type.
The following type indicators are available:
sufix | param type | example |
---|---|---|
<i> |
PDO::PARAM_INT |
"... WHERE id = :id", [":id<i>" => 42] |
<s> |
PDO::PARAM_STR |
"... WHERE name = :name", [":name<s>" => 'Mary'] |
<b> |
PDO::PARAM_BOOL |
"... WHERE active = :active", [":active<b>" => true] |
[i] |
PDO::PARAM_INT |
"... WHERE id IN(:ids)", [":ids[i]" => [42, 43]] |
[s] |
PDO::PARAM_STR |
"... WHERE name IN(:names)", [":names[s]" => ['Mary', 'Juliette']] |
[b] |
PDO::PARAM_BOOL |
"... WHERE (active, connected) IN((:flags))", [":flags[b]" => [true, false]] |
Some examples
Please look into /tests/
for more examples.
More functionality to come, please stay tuned ;-)
All versions of pdo-wrap with dependencies
ext-pdo Version *