PDO with some extra niceties
To install, simply run
composer require ancarda/pdo-plus
Wrap an existing PDO
object like so:
$pdo = new PDO(...);
$pdoPlus = new PDOPlus($pdo);
PDO Plus will set two attributes on your connection:
- Use
FETCH_ASSOC
to return associative arrays. - Use
ERRMODE_EXCEPTION
to throwPDOException
from methods.
From there, you can use the query
method which takes the SQL query as the
first parameter and the prepared statement params as the second parameter.
Query returns multiple rowsets for use with SQL Server and MySQL.
For everything else, you can use getPDO
.
For an RAII style of transactions, you can call createTransaction
.
For a more functional approach, use tryTransaction
which wraps the
transaction in a closure.