Skip to content

Instantly share code, notes, and snippets.

@mkhairul
Last active August 29, 2015 14:11
Show Gist options
  • Save mkhairul/6a8a0def23ef3ecd0ec1 to your computer and use it in GitHub Desktop.
Save mkhairul/6a8a0def23ef3ecd0ec1 to your computer and use it in GitHub Desktop.
Retrieve all records from Parse
<?php
// Based on http://stackoverflow.com/questions/17246991/parse-retrieve-more-then-1000-rows/17288679#17288679
function getAllRecords($className, $loopCount=0, $result=array())
{
$limit = 100;
$query = new ParseQuery($className);
$query->limit($limit);
$query->skip($limit * $loopCount);
try{
$query_result = $query->find();
if(count($query_result) > 0)
{
for($i = 0; $i < count($query_result); $i++)
{
$object = $query_result[$i];
$result[] = $object;
}
$loopCount++;
$result = getAllRecords($className, $loopCount, $result);
}
else
{
return $result;
}
} catch (ParseException $ex) {
echo "error!" . print_r($ex);
}
return $result;
}
$tmp = getAllRecords('sets');
echo 'total records fetched: ' . count($tmp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment