4

I am trying to query Parse.com using the new PHP SDK. I have installed everything necessary. I am having a problem querying though.

link:[https://www.parse.com/docs/php_guide#queries]

I have tried using this:

 require 'vendor/autoload.php';

 use Parse\ParseClient;
 use Parse\ParseObject;

 ParseClient::initialize('secret1','secret2', 'secret3');


 $query = new ParseQuery("TableName");
 $query->equalTo("email", "[email protected]");
 $results = $query->find();
 echo "Successfully retrieved " . count($results) . " scores.");

Any help would be greatly appreciated! Thank you!!!!


SOLVED using William George's help! Here is my updated code:

 require 'vendor/autoload.php';

 use Parse\ParseClient;
 use Parse\ParseObject;
 use Parse\ParseQuery;

 ParseClient::initialize('secret1','secret2', 'secret3');

 try{
 $query = new ParseQuery("TableName");
 $query->equalTo("email", "[email protected]");
 $results = $query->find();
 echo "Successfully retrieved " . count($results) . " scores.";
 } catch (Exception $e){
    echo $e->getMessage();
 }
5
  • What errors are you getting? Commented Aug 7, 2014 at 0:01
  • A blank screen on my php webpage when I added $query = new ParseQuery("TableName"); $query->equalTo("email", "[email protected]"); $results = $query->find(); echo "Successfully retrieved " . count($results) . " scores."); Commented Aug 7, 2014 at 0:02
  • If its not echoing anything then it must be crashing out somewhere. Are you running you web server locally, do you have error reporting enabled? Commented Aug 7, 2014 at 0:03
  • local webserver, do you think I am just missing a 'use' statement or something because it only crashes when I try to use a query? Commented Aug 7, 2014 at 0:04
  • Check your Apache error log. Commented Aug 7, 2014 at 0:05

1 Answer 1

8

Firstly you have a syntax error:

echo "Successfully retrieved " . count($results) . " scores.");

Should be

echo "Successfully retrieved " . count($results) . " scores.";

Secondly you do not include ParseQuery

use Parse\ParseQuery;

Also, the new PHP Parse framework throws exceptions all over the place.

Wrap your code in a try catch.

try {
   //parse code
} catch (\Exception $e){
   echo $e->getMessage();
}

What does the output say now?

Sign up to request clarification or add additional context in comments.

1 Comment

OUTPUT: Successfully retrieved 1 scores. :) Thank you so much for catching that extra ')' and telling me to use ParseQuery. You really helped me out. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.