jworksuk/extra-pdo

There is no license information available for the latest version (v0.1) of this package.

v0.1 2018-04-10 20:15 UTC

This package is not auto-updated.

Last update: 2024-04-24 22:55:01 UTC


README

Latest Version on Packagist Software License Build Status

A very thin layer over the PDO class.

Install

Via Composer

$ composer require jworksuk/extra-pdo

Usage

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();
}

Testing

$ composer test