Skip to content

Instantly share code, notes, and snippets.

@tiffany-taylor
Last active September 22, 2021 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiffany-taylor/e73a09c42d7a5eb1efa479735b5db85b to your computer and use it in GitHub Desktop.
Save tiffany-taylor/e73a09c42d7a5eb1efa479735b5db85b to your computer and use it in GitHub Desktop.
<?php
private function iterateSubmissions()
{
$nStartFrom = 0;
$nLimit = 500;
do {
$sQuery = 'SELECT blahblah FROM someTable WHERE blahblah = "somecondition" LIMIT ' . $nStartFrom . ', ' . $nLimit;
$oResults = $this->oDB->query($sQuery);
while ($kRow = $oResults->fetch(\PDO::FETCH_ASSOC)) {
yield $kRow;
}
$nStartFrom += $nLimit;
echo 'Start updated to ' . $nStartFrom;
} while ($kRow !== false);
}
<?php
private function coworkersMethod()
{
$nStartFrom = 0;
$nLimit = 500;
$bHasResults = true;
do {
$sQuery = 'SELECT blahblah FROM someTable WHERE blahblah = "somecondition" LIMIT ' . $nStartFrom . ', ' . $nLimit;
$oResults = $this->oDB->query($sQuery);
if ($oResults->rowCount()) {
while ($kRow = $oResults->fetch(\PDO::FETCH_ASSOC)) {
yield $kRow;
}
$nStartFrom += $nLimit;
} else {
$bHasResults = false;
}
} while ($bHasResults);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment