delboy1978uk/bone-db

Db package for Bone Framework

v1.3.0 2024-03-21 17:48 UTC

This package is auto-updated.

Last update: 2024-10-21 19:05:06 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License
Build Status Code Coverage Scrutinizer Code Quality

PDO Connection package for Bone Framework

installation

bone-db comes pre-installed as part of the core Bone Framework packages. Install the skeleton project https://github.com/delboy1978uk/bonemvc

usage

You should already have a bone-db.php config in your . Here is the Bone Framework Docker development environment settings:

<?php

return [
    'db' => [
        'driver' => 'pdo_mysql',
        'host' => 'mariadb',
        'dbname' => 'awesome',
        'user' => 'dbuser',
        'password' => '[123456]',
    ],
];

The two databases and passwords are due to old legacy crap. Will be sorted soon! ;-)

usage

You can inject your PDO connection into any of your classes via your Package registration class:

$pdoConnection = $c->get(PDO::class); // add a use statement too! 

convenience interface and trait

You can quickly get a PDO connection getter and setter into your controllers by using Bone\Db\HasDbTrait. You can also implement Bone\Db\DbProviderInterface and auto initialise it by passing into bone-controller Init class in the add to container factory method.

reference

Official Manual https://www.php.net/manual/en/book.pdo.php

An awesome detailed book on PDO https://phpdelusions.net/pdo