dev-master
9999999-dev https://github.com/pteague/useless-pdo-wrapperPDO Wrapper with Config
MIT
The Requires
- php >=5.3.10
- psr/log ~1.0
The Development Requires
by Patrick Teague
pdo
Wallogit.com
2017 © Pedro Peláez
PDO Wrapper with Config
PHP PDO Wrapper with Config, (*1)
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 );
}
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 );
PDO Wrapper with Config
MIT
pdo