定制 plumphp/plum-pdo 二次开发

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

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

plumphp/plum-pdo

最新稳定版本:v0.1.1

Composer 安装命令:

composer require plumphp/plum-pdo

包简介

Integrations PDO into Plum.

README 文档

README

Plum

PlumPdo integrates PDO into Plum. Plum is a data processing pipeline for PHP.

Build Status Windows Build status Scrutinizer Code Quality Code Coverage StyleCI

Developed by Florian Eckerstorfer in Vienna, Europe.

Installation

You can install Plum using Composer.

$ composer require plumphp/plum-pdo

Usage

Please refer to the Plum documentation for more information.

Currently PlumPdo contains PdoStatementReader to read data from a PDO-compatible database.

PdoStatementReader

Plum\PlumPdo\PdoStatementReader returns an iterator for the result set of a PDOStatement. The execute() method has to be called before.

use Plum\PlumPdo\PdoStatementReader;

$statement = $pdo->prepare('SELECT * FROM users WHERE age >= :min_age');
$statement->bindValue(':min_age', 18);
$statement->execute();

$reader = new PdoStatementReader($statement);
$reader->getIterator(); // -> \ArrayIterator
$reader->count();

The default behavior shown in the example above is that getIterator() will call fetchAll() on the PDOStatement and returns the result in the form of an \ArrayIterator. However, if the result set is very large and memory becomes a concern it is possible to fetch the result set row by row and yield each row to the workflow. You can invoke the behaviour by setting the option yield to true.

In the following example getIterator() returns a \Generator.

use Plum\PlumPdo\PdoStatementReader;

$statement = $pdo->prepare('SELECT * FROM users WHERE age >= :min_age');
$statement->bindValue(':min_age', 18);
$statement->execute();

$reader = new PdoStatementReader($statement, ['yield' => true]);
$iterator = $reader->getIterator(); // -> \Generator
foreach ($iterator as $row) {
}

The downside of using yield is that the reader is no longer countable and when invoking count() on such a reader a \RuntimeException will be thrown.

Change Log

Version 0.1.1 (6 October 2015)

  • Fix Plum version

Version 0.1 (22 April 2015)

  • Initial release

License

The MIT license applies to plumphp/plum-pdo. For the full copyright and license information, please view the LICENSE file distributed with this source code.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-16