PDO Connection package for Bone Framework
bone-db comes pre-installed as part of the core Bone Framework packages. Install the skeleton project https://github.com/delboy1978uk/bonemvc
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! ;-)
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!
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.
Official Manual https://www.php.net/manual/en/book.pdo.php
An awesome detailed book on PDO https://phpdelusions.net/pdo