PHPackages                             tomkyle/databases - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. tomkyle/databases

ActiveLibrary[Database &amp; ORM](/categories/database)

tomkyle/databases
=================

Creates generic connections to common database APIs, provided by easy-to-use connection factories. For multiple databases, a Service Locator helps you creating those factories.

1.0.12(11y ago)076[1 issues](https://github.com/tomkyle/Databases/issues)MITPHPPHP &gt;=5.3.0

Since Feb 19Pushed 11y ago1 watchersCompare

[ Source](https://github.com/tomkyle/Databases)[ Packagist](https://packagist.org/packages/tomkyle/databases)[ RSS](/packages/tomkyle-databases/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (19)Used By (0)

\#Databases Factory &amp; Service Locator

This Databases Connection Factory &amp; Service Locator creates generic connections to common database APIs, provided by easy-to-use connection factories. When working with multiple databases, a Service Locator helps you creating those factories. It supports [PDO](http://de.php.net/manual/en/book.pdo.php), [mysqli](http://www.php.net/manual/en/book.mysqli.php) and [Aura.SQL v1.3](https://github.com/auraphp/Aura.Sql/tree/master).

[![Build Status](https://camo.githubusercontent.com/eef229601c15cceee321476fed1df62b1fb61d1bb74c33ae3d461a60b1fb6e49/68747470733a2f2f7472617669732d63692e6f72672f746f6d6b796c652f4461746162617365732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/tomkyle/Databases)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/8a9da0a007a3b7b103e089ed540403b619be8eaba8d45d8845a8815b513230a5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746f6d6b796c652f4461746162617365732f6261646765732f7175616c6974792d73636f72652e706e673f733d35343033346434376237626634613437333135653934616636383564623465636435663631313936)](https://scrutinizer-ci.com/g/tomkyle/Databases/)[![Coverage Status](https://camo.githubusercontent.com/a474a28ed03d9e8d72e749087515a8db28386b4482d98fab8b3ca5c9af7c31c3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746f6d6b796c652f4461746162617365732f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/tomkyle/Databases?branch=master)

\##In a Nutshell ###Single Database

1. Setup **DatabaseConfig** with associative array or StdClass
2. Create **DatabaseProvider** with config object (Dependency Injection)
3. **Grab your connection** for the database API you like

[Show it already!](#getting-started-single-database)

\###Multiple Databases

1. **Describe database** connections in two-dimensional array or StdClass
2. Setup **DatabaseServiceLocator** with config object
3. Get **DatabaseProvider** from ServiceLocator
4. **Grab your connection** for the database API you like

[Show it already!](#multiple-databases-using-service-locator)

\##Installation

This library has no dependencies except from Fabien Potencier's [Pimple](https://github.com/fabpot/Pimple) library. It is installable and autoloadable via Composer. During installation, Composer will suggest to install [Aura.SQL v1.3](http://github.com/auraphp/Aura.Sql/tree/1.3.0), if you have not already. Install from command line or `composer.json` file:

\#####Command line

```
composer require tomykle/databases

```

\#####composer.json "require": { "tomkyle/databases": "~1.0" }

\##Getting started: Single Database

\###Overview Each `DatabaseProvider` needs some info about the database in question, passed as parameter implementing the `DatabaseConfigInterface`. A ready-to-use implementation is the `DatabaseConfig`, which itself is configured either by an associative array or StdClass.

Now that you have your `DatabaseConfig` ready, simply pass to new `DatabaseProvider` and grab the connection you like.

\###Example

```
