alexantr / fluentpdo-service-provider
This package is abandoned and no longer maintained.
No replacement package was suggested.
Pimple service provider for FluentPDO
dev-master / 1.0.x-dev
2016-08-10 15:05 UTC
Requires
- php: >=5.3.0
- fpdo/fluentpdo: 1.1.*
- pimple/pimple: ~3.0
This package is not auto-updated.
Last update: 2022-02-01 12:46:43 UTC
README
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)); } });