Package Data | |
---|---|
Maintainer Username: | belgattitude |
Package Create Date: | 2016-01-01 |
Package Last Update: | 2020-11-28 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-14 15:09:46 |
Package Statistics | |
---|---|
Total Downloads: | 1,474 |
Monthly Downloads: | 2 |
Daily Downloads: | 1 |
Total Stars: | 7 |
Total Watchers: | 4 |
Total Forks: | 0 |
Total Open Issues: | 1 |
Minimalist (but universal) database wrapper to rule them all (and to not choose).
mysqli
, pdo_mysql
, pdo_sqlite
drivers.zend-db
, laravel
and doctrine
.
For PHP 5.6+, 7.0+ or HHVM >= 3.9 look at version 1.3. For PHP < 5.6 take the 1.2 version
Instant installation via composer.
$ composer require soluble/dbwrapper
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);
Execute SQL
<?php
$results = $adapter->query("select * from my_table");
foreach($results as $result) {
echo $result['my_column'];
}
Execute SQL
<?php
$connection = $adapter->getConnection();
echo $connection->getCurrentSchema();
echo $connection->getHost();
$resource = $connection->getResource();
The DbWrapper\AdapterFactory
allows to instanciate an Adapter from en existing connection link or resource.
| Methods | Return | Comment |
|-----------------------------------------------|--------------------|-------------------------------------|
| static createAdapterFromResource($resource)
| AdapterInterface
| From existing resource (mysqli, pdo) |
| static createAdapterFromDbal2($dbal)
| AdapterInterface
| From doctrine/dbal connection |
| static createAdapterFromCapsule5($capsule)
| AdapterInterface
| From Laravel connection |
| static createAdapterFromZendDb2($zend)
| AdapterInterface
| From zend-db connection |
The DbWrapper\Adapter\AdapterInterface
provides common operation on your database.
| Methods | Return | Description |
|--------------------------|---------------|-----------------------------------------------|
| query($query)
| Resultset
| Iterable results DbWrapper\Result\Resultset
|
| execute($query)
| void
| Execute command (set, ...) |
| quoteValue($value)
| string
| Quote value |
| getConnection()
| ConnectionInterface
| ConnectionInterface |
The DbWrapper\Result\Resultset
is can be easily iterated through a simple foreach loop.
Additionnaly you can call the following methods :
| Methods | Return | Description |
|---------------------------------|---------------|-----------------------------------------------|
| count()
| int
| Count the number of results |
The DbWrapper\Connection\ConnectionInterface
provides information about your connection
| Methods | Return | Description |
|--------------------------|---------------|-----------------------------------------------|
| getCurrentSchema()
| string|false
| Return current schema |
| getResource()
| mixed
| Return internal connection (pdo, mysqli...) |
| getHost()
| string
| Return server hostname or IP |
soluble/dbwrapper
supports natively :
| Database | PHP ext | |------------|------------------------------------------------------| | Mysql | mysqli, pdo_mysql | | MariaDb | mysqli, pdo_mysql | | Sqlite | pdo_sqlite |
For examples, see the native drivers doc
Some of the supported databases can be (incomplete list) :
| Database | Doctrine | Laravel | Zend | |------------|------------|---------|-----------| | Mysql | Yes | Yes | Yes | | MariaDb | Yes | Yes | Yes | | Sqlite | Yes | Yes | Yes | | Oracle | Yes | No | Yes | | Sqlserver | Yes | Yes | Yes | | Postgres | Yes | Yes | Yes | (...)
For examples, see the userland drivers doc
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.
Contribution and pull request are more than welcome, see the contribution guide