alexantr / fluentpdo-service-provider
Pimple service provider for FluentPDO
Installs: 40
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/alexantr/fluentpdo-service-provider
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)); } });