PHPackages                             pollen-solutions/database - 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. pollen-solutions/database

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

pollen-solutions/database
=========================

Pollen Solutions - Database Component - Database toolkit for PHP

v1.0.1(4y ago)0452MITPHPPHP ^7.4 || ^8.0

Since Aug 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/pollen-solutions/database)[ Packagist](https://packagist.org/packages/pollen-solutions/database)[ Docs](https://www.presstify.com/pollen-solutions/database/)[ RSS](/packages/pollen-solutions-database/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (6)Versions (4)Used By (2)

Database
========

[](#database)

[![Latest Stable Version](https://camo.githubusercontent.com/77a562e04b6cd9f1de93fe852217edfd1930e07946019d6bbd838eda890e62cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706f6c6c656e2d736f6c7574696f6e732f64617461626173652e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/pollen-solutions/database)[![MIT Licensed](https://camo.githubusercontent.com/daa52099573be5a50c320c4387496400f2f722e49f86a42db8d5778130d3582d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e3f7374796c653d666f722d7468652d6261646765)](LICENSE.md)[![PHP Supported Versions](https://camo.githubusercontent.com/d9d71d0b69072c51e1ff7adfdb6270f896f75787500ce6437120e23727c081d1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d2533453d372e342d3838393242463f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://www.php.net/supported-versions.php)

**Database** Component is a database toolkit for PHP. At the moment, it uses the Laravel database library as its sole engine.

Installation
------------

[](#installation)

```
composer require pollen-solutions/database
```

Basic Usage
-----------

[](#basic-usage)

### Add the default connexion

[](#add-the-default-connexion)

```
use Pollen\Database\DatabaseManager;

$db = new DatabaseManager();

$db->addConnection([
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'pollen-solutions',
    'username'  => 'root',
    'password'  => 'root',
    'charset'   => 'utf8mb4',
    'collation' => 'utf8mb4_general_ci',
    'prefix'    => 'xyz_',
]);
```

### Using The Schema Builder

[](#using-the-schema-builder)

```
use Illuminate\Database\Schema\Blueprint;
use Pollen\Database\DatabaseManagerInterface;

/** @var DatabaseManagerInterface $db */
$schema = $db->getConnection()->getSchemaBuilder();
$schema->create('posts', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title');
    $table->longText('content')->nullable();
    $table->timestamps();
});
```

More usage informations on [Laravel online official documentation](https://laravel.com/docs/8.x/migrations#tables)

### Using The Query Builder

[](#using-the-query-builder)

```
use Pollen\Database\DatabaseManagerInterface;

/** @var DatabaseManagerInterface $db */
$posts = $db->getConnection()->table('posts')->get();

var_dump($posts);
exit;
```

More usage informations on [Laravel online official documentation](https://laravel.com/docs/8.x/queries)

### Optional configuration

[](#optional-configuration)

#### Static methods call

[](#static-methods-call)

```
use Pollen\Database\DatabaseManagerInterface;
use Pollen\Database\DatabaseManager as DB;

/** @var DatabaseManagerInterface $db */
$db->setAsGlobal();

// Now you can call DatabaseManager methods as static.
$posts = DB::table('posts')->get();

var_dump($posts);
exit;
```

Eloquent model
--------------

[](#eloquent-model)

### Prerequisite

[](#prerequisite)

```
use Pollen\Database\DatabaseManagerInterface;

/** @var DatabaseManagerInterface $db */
$db->bootEloquent();
```

Advanced Usage
--------------

[](#advanced-usage)

### Configuration parameters

[](#configuration-parameters)

#### MySQL

[](#mysql)

```
