antevenio/pdo-mysql-query-linker

PHP 库,允许通过 mysql pdo 数据库连接将不同物理数据库的查询链接起来

0.0.16 2023-04-18 15:02 UTC

README

Latest Stable Version Total Downloads License Build Status Code Climate

PHP 库,允许通过 mysql pdo 数据库连接将不同物理数据库的查询链接起来。

这是什么玩意儿

完成后再解释。

安装

使用 composer 添加依赖

composer require antevenio/pdo-mysql-query-linker

使用示例

<?php
$originPdo = new PDO('mysql:host=host1;dbname=kidsshouting', 'myuser', 'mypass');
$targetPdo = new PDO('mysql:host=host2;dbname=kidsshouting', 'myuser', 'mypass');

$linker = (new \PdoMysqlQueryLinker\Linker\Factory())->create()
    ->origin(
        $originPdo, 
        "select * from table_in_origin where column = 'something'"
        )
    ->target(
        $targetPdo, 
        "delete from table_in_destination inner join {origin} using(column)"
        );

// Get a limit clause block based iterator
$iterator = $linker->getIterator(10000);
foreach ($iterator as $row) {
    // do your stuff;
}
$linker->close();

// Get a pdo statement
$stmt = $linker->execute();
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($rows as $row) {
    // do your stuff;
}
$linker->close();

// Get just the resolved query to run in destination adapter
$query = $linker->getQuery();
$stmt = $targetPdo->query($query);
$linker->close();