aura / sql
A PDO extension that provides lazy connections, array quoting, query profiling, value binding, and convenience methods for common fetch styles. Because it extends PDO, existing code that uses PDO can use this without any changes to the existing code.
Installs: 1 767 596
Dependents: 52
Suggesters: 7
Security: 0
Stars: 557
Watchers: 43
Forks: 100
Open Issues: 7
Requires
- php: >=8.1
- ext-pdo: *
- psr/log: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- pds/skeleton: ~1.0
- phpunit/phpunit: ^9.5
- 6.x-dev
- 5.x-dev
- 5.0.2
- 5.0.1
- 5.0.0
- 4.x-dev
- 4.0.0
- 3.x-dev
- 3.1.0
- 3.0.0
- 3.0.0-beta1
- 3.0.0-alpha1
- 2.x-dev
- 2.6.0
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.1
- 2.0.0
- 2.0.0-beta1
- 1.x-dev
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0
- dev-harikt-patch-2
- dev-harikt-patch-1
- dev-issue-231
- dev-3.x-actions
- dev-2.x-locator-profiling
This package is auto-updated.
Last update: 2024-12-23 14:26:44 UTC
README
Provides an extension to the native PDO along with a profiler and connection locator. Because ExtendedPdo is an extension of the native PDO, code already using the native PDO or typehinted to the native PDO can use ExtendedPdo without any changes.
Added functionality in Aura.Sql over the native PDO includes:
-
Lazy connection. ExtendedPdo connects to the database only on method calls that require a connection. This means you can create an instance and not incur the cost of a connection if you never make a query.
-
Decoration. DecoratedPdo can be used to decorate an existing PDO instance. This means that a PDO instance can be "extended" at runtime to provide the ExtendedPdo behaviors.
-
Array quoting. The
quote()
method will accept an array as input, and return a string of comma-separated quoted values. -
New
perform()
method. Theperform()
method acts just likequery()
, but binds values to a prepared statement as part of the call. In addition, placeholders that represent array values will be replaced with comma- separated quoted values. This means you can bind an array of values to a placeholder used with anIN (...)
condition when usingperform()
. -
New
fetch*()
methods. The newfetch*()
methods provide for commonly-used fetch actions. For example, you can callfetchAll()
directly on the instance instead of having to prepare a statement, bind values, execute, and then fetch from the prepared statement. All of thefetch*()
methods take an array of values to bind to to the query statement, and use the newperform()
method internally. -
New
yield*()
methods. These are complements to thefetch*()
methods thatyield
results instead ofreturn
ing them. -
Exceptions by default. ExtendedPdo starts in the
ERRMODE_EXCEPTION
mode for error reporting instead of theERRMODE_SILENT
mode. -
Profiler. An optional query profiler is provided, along with an interface for other implementations, that logs to any PSR-3 interface.
-
Connection locator. A optional lazy-loading service locator is provided for picking different database connections (default, read, and write).
Installation and Autoloading
This package is installable and PSR-4 autoloadable via Composer as aura/sql.
Alternatively, download a release, or clone this repository, then map the
Aura\Sql\
namespace to the package src/
directory.
Dependencies
This package requires PHP 8.1 or later; it has also been tested on PHP 8.1-8.2. We recommend using the latest available version of PHP as a matter of principle.
Aura library packages may sometimes depend on external interfaces, but never on external implementations. This allows compliance with community standards without compromising flexibility. For specifics, please examine the package composer.json file.
Quality
This project adheres to Semantic Versioning.
To run the unit tests at the command line, issue composer install
and then
./vendor/bin/phpunit
at the package root. (This requires Composer to be
available as composer
.)
This package attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.
Community
To ask questions, provide feedback, or otherwise communicate with other Aura users, please join our Google Group, follow @auraphp, or chat with us on Freenode in the #auraphp channel.
Documentation
This package is fully documented here.