herrera-io/silex-pdo

A simple PDO service provider.

Installs: 23 010

Dependents: 1

Stars: 16

Watchers: 2

Forks: 1

Language: PHP

1.2.1 2013-11-26 17:05 UTC

README

Build Status

A simple PDO service provider.

Summary

A stupid simple PDO service provider. I cannot get any more clear than this.

Installation

Add it to your list of Composer dependencies:

$ composer require "herrera-io/silex-pdo=1.*"

Usage

use Herrera\Pdo\PdoServiceProvider;
use Silex\Application;

$app = new Application();
$app->register(
    new PdoServiceProvider(),
    array(
        'pdo.dsn' => 'pdo_mysql:dbname=test;host=127.0.0.1',
        'pdo.username' => 'username', // optional
        'pdo.password' => 'password', // optional
        'pdo.options' => array( // optional
            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
        )
    )
);

$pdo = $app['pdo'];

You can also use the PdoTrait to add a prepare method to your application:

use Herrera\Pdo\PdoTrait;
use Silex\Application;

class MyApp extends Application
{
    use PdoTrait;
}

You will still need to register the service provider.

If debugging is enabled and Monolog is available, a logging version of PDO will be used to log queries and their execution time.