定制 useless/pdo-wrapper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

useless/pdo-wrapper

Composer 安装命令:

composer require useless/pdo-wrapper

包简介

PDO Wrapper with Config

关键字:

README 文档

README

PHP PDO Wrapper with Config

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.

<?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.

<?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.

<?php
use Useless\Pdo\Wrapper;

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

$pdo = new Wrapper( $config );

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-12-31