GithubHelp home page GithubHelp logo

belgattitude / soluble-dbwrapper Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 0.0 464 KB

Extra minimalist but universal database wrapper

License: MIT License

PHP 100.00%
database database-adapter php minimalist interop mysql postgresql sqlite3 mssql doctrine

soluble-dbwrapper's Introduction

soluble/dbwrapper

PHP 7.1+ Build Status codecov Scrutinizer Quality Score Latest Stable Version Total Downloads License

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 and doctrine.
    • 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

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.

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

AdapterInterface

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

Resultset

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

ConnectionInterface

The DbWrapper\Connection\ConnectionInterface provides information about your connection

Methods Return Description
getCurrentSchema() `string false`
getResource() mixed Return internal connection (pdo, mysqli...)
getHost() string Return server hostname or IP

Supported databases

Native

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

Userland implementations

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

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

Coding standards

soluble-dbwrapper's People

Contributors

belgattitude avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.