Skip to content
This repository has been archived by the owner. It is now read-only.
Pimple service provider for FluentPDO
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
composer.json

README.md

FluentPDO Service Provider

Pimple service provider for FluentPDO.

Installation

Install provider through Composer:

composer require alexantr/fluentpdo-service-provider "~1.0@dev"

Registering and configuration

$app->register(new \Alexantr\Pimple\Provider\FluentPdoServiceProvider(), array(
    'fpdo.pdo_options' => array(
        'dsn' => 'mysql:dbname=blog;host=localhost;charset=UTF8',
        'username' => 'username',
        'password' => 'password',
    ),
    'fpdo.debug' => false,
));

Usage example

To get first ten records for table "posts":

$posts = $app['fpdo']
    ->from('article')
    ->where('published_at > ?', $date)
    ->orderBy('published_at DESC')
    ->limit(5);

For more examples see FluentPDO documentation.

Enable debugging

Log queries to STDERR (for console debugging):

$app['fpdo.debug'] = true;

or set callback:

$app['fpdo.debug'] = $app->protect(function (\BaseQuery $query) use ($app) {
    // simple example with logger
    if (isset($app['logger']) && $app['logger'] !== null) {
        $debug_line = array();
        $debug_line[] = 'Query: ' . $q->getQuery(false);
        $debug_line[] = 'Params: ' . implode(', ', $q->getParameters());
        $debug_line[] = 'RowCount: ' . ($q->getResult() ? $q->getResult()->rowCount() : 0);
        $debug_line[] = 'Time: ' . $q->getTime();
        $app['logger']->debug(implode(', ', $debug_line));
    }
});
You can’t perform that action at this time.