library/Haste/Database/QueryHelper.php
public static function processInPieces($strCountQuery, $strQuery, $callback = null, $strKey = null, $intBulkSize = 5000)
    {

        $objTotal = \Database::getInstance()->execute($strCountQuery);

        if ($objTotal->total < 1)
        {
            return false;
        }

        $intBulkSize = intval($intBulkSize);
        $intTotal    = $objTotal->total;
        $intCycles   = $intTotal / $intBulkSize;

        for ($i = 0; $i <= $intCycles; $i++)
        {
            $objResult = \Database::getInstance()->prepare($strQuery)->limit($intBulkSize, $i * $intBulkSize)->execute();

            if ($objResult->numRows < 1)
            {
                return false;
            }

            if (is_callable($callback))
            {
                $arrReturn = [];

                while (($arrRow = $objResult->fetchAssoc()) !== false)
                {
                    if ($strKey)
                    {
                        $arrReturn[$arrRow[$strKey]] = $arrRow;
                        continue;
                    }

                    $arrReturn[] = $arrRow;
                }

                call_user_func_array($callback, [$arrReturn]);
            }
        }

        return $intTotal;
    }
public static function processInPieces($strCountQuery, $strQuery, $callback = null, $strKey = null, $intBulkSize = 5000)
    {

        $objTotal = \Database::getInstance()->execute($strCountQuery);

        if ($objTotal->total < 1)
        {
            return false;
        }

        $intBulkSize = intval($intBulkSize);
        $intTotal    = $objTotal->total;
        $intCycles   = $intTotal / $intBulkSize;

        for ($i = 0; $i <= $intCycles; $i++)
        {
            $objResult = \Database::getInstance()->prepare($strQuery)->limit($intBulkSize, $i * $intBulkSize)->execute();

            if ($objResult->numRows < 1)
            {
                return false;
            }

            if (is_callable($callback))
            {
                $arrReturn = [];

                while (($arrRow = $objResult->fetchAssoc()) !== false)
                {
                    if ($strKey)
                    {
                        $arrReturn[$arrRow[$strKey]] = $arrRow;
                        continue;
                    }

                    $arrReturn[] = $arrRow;
                }

                call_user_func_array($callback, [$arrReturn]);
            }
        }

        return $intTotal;
    }
public static function processInPieces ( $ strCountQuery , $ strQuery , $ callback = null , $ strKey = null , $ intBulkSize = 5000 ) { $ objTotal = \ Database :: getInstance ( ) -> execute ( $ strCountQuery ) ; if ( $ objTotal -> total < 1 ) { return false ; } $ intBulkSize = intval ( $ intBulkSize ) ; $ intTotal = $ objTotal -> total ; $ intCycles = $ intTotal / $ intBulkSize ; for ( $ i = 0 ; $ i <= $ intCycles ; $ i ++ ) { $ objResult = \ Database :: getInstance ( ) -> prepare ( $ strQuery ) -> limit ( $ intBulkSize , $ i * $ intBulkSize ) -> execute ( ) ; if ( $ objResult -> numRows < 1 ) { return false ; } if ( is_callable ( $ callback ) ) { $ arrReturn = [ ] ; while ( ( $ arrRow = $ objResult -> fetchAssoc ( ) ) !== false ) { if ( $ strKey ) { $ arrReturn [ $ arrRow [ $ strKey ] ] = $ arrRow ; continue ; } $ arrReturn [ ] = $ arrRow ; } call_user_func_array ( $ callback , [ $ arrReturn ] ) ; } } return $ intTotal ; }
Process a query in pieces, run callback within each cycle

@param  string   $strCountQuery The query that count the total rows, must contain "Select COUNT(*) as total"
@param   string  $strQuery      The query, with the rows that should be iterated over
@param  callable $callback      A callback that should be triggered after each cycle, contains $arrRows of current cycle
@param string    $strKey        The key of the value that should be set as key identifier for the returned result array entries
@param int       $intBulkSize   The bulk size

@return bool|int False if nothing to do, otherwise return the total number of processes entities
Process a query in pieces run callback within each cycle