Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying Parse.com using PHP SDK

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();
 }
like image 373
MadsterMaddness Avatar asked Feb 12 '23 07:02

MadsterMaddness


1 Answers

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?

like image 175
William George Avatar answered Feb 15 '23 11:02

William George