soluble / dbwrapper
Universal minimalist database wrapper
Installs: 1 476
Dependents: 4
Suggesters: 1
Security: 0
Stars: 7
Watchers: 4
Forks: 0
Open Issues: 1
Requires
- php: ^7.1
- ext-pdo: *
Requires (Dev)
- captainhook/plugin-composer: ^3.0
- doctrine/common: >=2.5.0|<3.0.0
- doctrine/dbal: >=2.5.0|<3.0.0
- friendsofphp/php-cs-fixer: ^2.11
- illuminate/database: >=4.0.0|<6.0.0
- phpstan/phpstan: ^0.10.5
- phpstan/phpstan-phpunit: ^0.10
- phpstan/phpstan-strict-rules: ^0.10.1
- phpunit/phpunit: ^7.5
- zendframework/zend-db: >=2.2.0|<3.0.0
README
Introduction
Minimalist (but universal) database wrapper to rule them all (and to not choose).
Features
- Provide a generic API for handling database access across various implementations.
- Lightweight, framework adaptive and agnostic.
- Natively supports
mysqli
,pdo_mysql
,pdo_sqlite
drivers. - Bridged implementations of
zend-db
,laravel
anddoctrine
.- Access to Oracle, SQL-Server, PostgreSql,...
- Allow to develop database portable libraries.
- Adhere to soluble programming standards.
Requirements
- PHP 7.1 optional ext-mysqli/PDO
For PHP 5.6+, 7.0+ or HHVM >= 3.9 look at version 1.3. For PHP < 5.6 take the 1.2 version
Documentation
- Manual in progress and API documentation available.
Installation
Instant installation via composer.
$ composer require soluble/dbwrapper
Quick start
Connection
Create an adapter from an existing Mysqli connection
<?php use Soluble\DbWrapper; $conn = new \mysqli($hostname,$username,$password,$database); $conn->set_charset($charset); $adapter = DbWrapper\AdapterFactory::createAdapterFromResource($conn);
Querying database
Execute SQL
<?php $results = $adapter->query("select * from my_table"); foreach($results as $result) { echo $result['my_column']; }
Get connection infos
Execute SQL
<?php $connection = $adapter->getConnection(); echo $connection->getCurrentSchema(); echo $connection->getHost(); $resource = $connection->getResource();
API methods
AdapterFactory
The DbWrapper\AdapterFactory
allows to instanciate an Adapter from en existing connection link or resource.
AdapterInterface
The DbWrapper\Adapter\AdapterInterface
provides common operation on your database.
Resultset
The DbWrapper\Result\Resultset
is can be easily iterated through a simple foreach loop.
Additionnaly you can call the following methods :
ConnectionInterface
The DbWrapper\Connection\ConnectionInterface
provides information about your connection
Supported databases
Native
soluble/dbwrapper
supports natively :
For examples, see the native drivers doc
Userland implementations
Some of the supported databases can be (incomplete list) :
For examples, see the userland drivers doc
Motivations
Initially the reason behind the development of soluble/dbwrapper
was to get
a reliable and lightweight library to abstract the PDO_mysql
and mysqli
driver interfaces.
Later on, while developing some libraries, I feel the need for something more framework agnostic that could still be integrated easily into any modern framework. The userland drivers idea was born.
Contributing
Contribution and pull request are more than welcome, see the contribution guide