php-vivace/db

View on GitHub
docs/1.INITIALIZATION.md

Summary

Maintainability
Test Coverage
## Initialize a Storage instance

Instantiate a driver.
The driver is needed to access the storage used, it is he who is responsible for building queries and fetching data.
In this example, the driver requires a PDO instance.
```php
use \vivace\db\sql;
...
$driver = new sql\MySQL\Driver($pdoInstance);
```
Next you need initialize storage.
First argument is driver, second is schema(aka table,collection) name
```php
$users = new sql\Storage($driver, 'users');
``` 
If you have several schemas with the same name, you can specify a particular database via a dot.
```php
$users = new sql\Storage($driver, 'app.users');
``` 

One driver can be used for multiple storage
```php
$books = new sql\Storage($driver, 'app.books');
$authors = new sql\Storage($driver, 'authors');
```
For a better understanding, you can look at the following interfaces and classes
- __vivace\db\Storage__ - An interface that describes the main storage capabilities.
- __vivace\db\sql\Storage__ - An implementation __vivace\db\Storage__ for sql databases.
- __vivace\db\sql\Driver__ - An interface that describes the main driver capabilities.
- __vivace\db\sq\PostgreSQL\Driver__ - An implementation of __vivace\db\sql\Driver__ for working with postgresql database 
- __vivace\db\sq\MySQL\Driver__ - An implementation of __vivace\db\sql\Driver__ for working with mysql database