1. Go to this page and download the library: Download dromru/iterable-dbal 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/ */
dromru / iterable-dbal example snippets
/**
* @var \Doctrine\DBAL\Connection $connection
*/
$iterator = new \Drom\IterableUtils\Dbal\BatchedMinMaxQueryIterator(
$batchSize = 1000,
\Closure::fromCallable([$connection, 'fetchFirstColumn']),
<<<'SQL'
SELECT id
FROM `test`.`sample_table`
WHERE field1 IN (:param1)
WHERE id BETWEEN :minId AND :maxId
SQL,
[
'minId' => 1,
'maxId' => 1_000_000_000,
'field1' => [1, 2, 3],
],
[
'minId' => \Doctrine\DBAL\ParameterType::INTEGER,
'maxId' => \Doctrine\DBAL\ParameterType::INTEGER,
'field1' => \Doctrine\DBAL\Connection::PARAM_INT_ARRAY,
]
);
foreach ($iterator as $id) {
echo PHP_EOL . $id;
}
$ids = [1, 2, /* ... */, 1_000_000_000];
/**
* @var \Doctrine\DBAL\Connection $connection
*/
$iterator = new \Drom\IterableUtils\Dbal\BatchedIdsQueryIterator(
$batchSize = 1000,
\Closure::fromCallable([$connection, 'fetchAllAssociative']),
<<<'SQL'
SELECT *
FROM `test`.`sample_table`
WHERE field1 = :param1
WHERE id in (:ids)
SQL,
[
'ids' => $ids,
'param1' => 1,
],
[
'ids' => \Doctrine\DBAL\Connection::PARAM_INT_ARRAY,
'param1' => \Doctrine\DBAL\ParameterType::INTEGER,
]
);
foreach ($iterator as $item) {
echo PHP_EOL;
print_r($item);
echo PHP_EOL;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.