PHP code example of antevenio / pdo-mysql-query-linker

1. Go to this page and download the library: Download antevenio/pdo-mysql-query-linker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

antevenio / pdo-mysql-query-linker example snippets



$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();