spacemonkey
spacemonkey

Reputation: 2550

Parse - PHP SDK unable to load records

I tested the installation using the parse.com instructions and it worked (recorded was added to table). Now I am trying to retrieve the information in the table (2 records), and all I have is a blank page with no errors.

Here is the code:

<?php
require 'vendor/autoload.php';

use Parse\ParseClient;
use Parse\ParseObject;

ParseClient::initialize('djdksjdkks', 'jdksjdksjdksd', 'jdksjdjsdjskdsjdjsdks');

?>

and then later in the page the code I expect to show something:

<?php
                        $query = new ParseQuery("Donations");
                        //$query->equalTo("playerName", "Dan Stemkoski");
                        $results = $query->find();

                        //echo "Successfully retrieved " . count($results) . " scores.");
                        for ($i = 0; $i < count($results); $i++) { 
                            $object = $results[$i];
                            echo $object->getObjectId() . ' - ' . $object->get('fullname'));
                         }
                      ?>

Please help out...I read that if there is a syntax mistake, PHP tends to load a white screen.

Upvotes: 1

Views: 505

Answers (2)

saravankg
saravankg

Reputation: 913

I think you miss the use Parse\ParseQuery; at your code.

Upvotes: 2

Dinsen
Dinsen

Reputation: 2289

Try this

$query = new ParseQuery("Donations");
$results = $query->find();

foreach ( $results as $result ) {
    // echo user Usernames
    echo $result->getObjectId() . ' - ' . $result->get('fullname'));
}

If you want to track errors, then use a try catch

$query = new ParseQuery("Donations");
try {
    $results = $query->find();
    // The objects was retrieved successfully.
} catch (ParseException $ex) {
    // The object was not retrieved successfully.
    // error is a ParseException with an error code and message.
    echo $ex->getMessage(); 
}

foreach ( $results as $result ) {
    // echo user Usernames
    echo $result->getObjectId() . ' - ' . $result->get('fullname'));
}

Upvotes: 0

Related Questions