Download the PHP package rain1/pdo-powered without Composer
On this page you can find all versions of the php package rain1/pdo-powered. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package pdo-powered
PDOPowered is a wrapper for PDO providing following features:
- lazy connection The PDO instance is created only when needed. Configured credentials are deleted after the connection.
- with
$db->onConnect($closure)
it's possible to do something after the connection.
- with
- reconnect on failure try to reconnect if the connection fails (for
PDOPowered::$MAX_TRY_CONNECTION
tries).- with
$db->onConnectionFailure($closure)
it's possible to do something after every connection fail (for example a sleep and/or error reporting)
- with
- fast query params prepare and execute are called in
query
method.$db->query("SELECT ?,?,?", [1,2,3])
- Query method returns a wrapper for
PDOStatement
with powered methods:- fetchObjects call
fetchObject
for each row and store the result in array - getPDOStatement for fetch the native PDOStatement.
- fetchObjects call
- fast queries there are helpers for fast query:
- insert for fast insert
$db->insert("tableName",$arrayValues)
returns the last insert id. - update for fast update
$db->update("tableName", $valuesToUpdate, $arrayCondition)
returns the count of affected rows. - insertOnDuplicateKeyUpdate for insert on duplicate key update
$db->insertOnDuplicateKeyUpdate($tableName, $arrayValues)
returns the last insert id. - delete for fast delete
$db->delete("tableName", $arrayWhereCondition)
returns the count of affected rows
- insert for fast insert
- easy debug with
$db->onDebug($closure)
it's possible to access to debug output and do your stuff (log in file, send to stdoutput and so on) - access to native PDO instance extending
PDOPowered
you have access togetPDO()
method for any needs.
Basic Usage
Installation
or checkout https://github.com/LucaRainone/pdo-powered.git
or download here (https://github.com/LucaRainone/pdo-powered/archive/master.zip)
Get Started
An implementation of rain1\PDOPowered\Config\ConfigInterface must be passed to the constructor. We provide following implementations:
or equivalent
So, we build the instance in this way:
It's possible to use PDOPowered with a pre-existent PDO instance
The library provides shortcuts for insert / update / delete and update on duplicate key:
The method query
returns a wrapper of \PDOStatement. Availabile methods:
fetch
fetchAll
fetchObject
fetchColumn
rowCount
closeCursor
getPDOStatement
returns the native PDOStatmenet (for any evenience)fetchObjects
returns an array containing all of the result offetchObject
call
Advanced usage:
Following events are triggered:
- connectionFailure
- connect
- debug
We provide an helper for easy debug
Other options:
Param hints
PDOPowered automatically considers value param strings as \PDO::PARAM_STR, and value integer as \PDO::PARAM_INT. For any evenience, you can do it explicitly:
And generally you can use every PDO Param supported:
or build yourself a new Param type, implementing \rain1\PDOPowered\Param\ParamInterface
.
For example as bonus we have:
this is equivalent to:
Real use case (try me at home)
You need to create a database "test".
All versions of pdo-powered with dependencies
ext-pdo Version *
ext-json Version *