A very thin layer over the PDO class.
Via Composer
$ composer require jworksuk/extra-pdo
require_once '/path/to/vendor/autoload.php';
use JWorksUK\ExtraPDO;
use Acme\Model;
$pdo = ExtraPDO::createMySqlConnection(
'databaseName',
'databaseHost',
'databaseUser',
'databasePassword'
);
$model = $pdo
->executeStatement('SELECT * FROM todos WHERE id=:id', [
'id' => '15983acf-022f-303a-bfef-a096eaebbf7c'
])
->fetchAndMap(function ($row) {
return new Model(
$row['id'],
$row['name'],
$row['list_id'],
new \DateTime($row['updated_at']),
new \DateTime($row['created_at'])
);
});
$model->doModelThing();
$models = $pdo
->executeStatement('SELECT * FROM todos WHERE list_id=:listId', [
'listId' => '05aab6f6-e991-3c59-a980-832cca75c578'
])
->fetchAllAndMap(function ($row) {
return new Model(
$row['id'],
$row['name'],
$row['list_id'],
new \DateTime($row['updated_at']),
new \DateTime($row['created_at'])
);
});
foreach ($models as $model) {
$model->doModelThing();
}
$ composer test