2017 © Pedro Peláez
 

library pdo-wrapper

PDO Wrapper with Config

image

useless/pdo-wrapper

PDO Wrapper with Config

  • Monday, January 5, 2015
  • by pteague
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Useless PDO Wrapper

PHP PDO Wrapper with Config, (*1)

Configuration Factory

The Config\Factory let's you dynamically instantiate a class that implements the ConfigInterface in case your current configurations are not using a standard PDO DSN., (*2)

<?php
use PDO;
use Useless\Pdo\Config\Factory;
use Useless\Pdo\Config\AbstractConfig;

$config = array(
    AbstractConfig::DRIVER => Factory::CONFIG_MYSQL,
    AbstractConfig::HOST => 'localhost',
    AbstractConfig::DBNAME => 'test',
    AbstractConfig::CHARSET => 'utf8',
    AbstractConfig::USERNAME => 'username',
    AbstractConfig::PASSWORD => 'password',
);

$factory = new Factory();
$config = $factory->getConfig( $config );
$pdo = new PDO( $config->getDsn(), $config->getUsername(), $config->getPassword(), $config->getOptions() );
foreach ( $config->getAttributes() as $attribute => $value ) {
    $pdo->setAttribute( $attribute, $value );
}

Lazy Connection

Instantiation can be done the same as with the native PDO class: a data source name, username, password, and driver options. An additional parameter allows for passing attributes to be set after the connection is made., (*3)

<?php
use Useless\Pdo\Wrapper;

$pdo = new Wrapper(
    'mysql:localhost;dbname=test;charset=utf8',
    'username',
    'password',
    array(), # driver options as key/value pairs
    array()  # attributes to be set after connection as key/value pairs
);

Or you may instantiate with a class that extends the Useless\Pdo\ConfigInterface., (*4)

<?php
use Useless\Pdo\Wrapper;

$config = $factory->getConfig( $config );

$pdo = new Wrapper( $config );

The Versions

05/01 2015

dev-master

9999999-dev https://github.com/pteague/useless-pdo-wrapper

PDO Wrapper with Config

  Sources   Download

MIT

The Requires

 

The Development Requires

by Patrick Teague

pdo