使用PHP SDK查询Parse.com

时间:2014-08-06 23:57:02

标签: php parse-platform

我正在尝试使用新的PHP SDK查询Parse.com。我安装了所有必要的东西。我在查询时遇到了问题。

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

我尝试过使用它:

 require 'vendor/autoload.php';

 use Parse\ParseClient;
 use Parse\ParseObject;

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


 $query = new ParseQuery("TableName");
 $query->equalTo("email", "email@me.com");
 $results = $query->find();
 echo "Successfully retrieved " . count($results) . " scores.");

任何帮助将不胜感激!谢谢!!!!


使用William George的帮助解决了!这是我更新的代码:

 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@me.com");
 $results = $query->find();
 echo "Successfully retrieved " . count($results) . " scores.";
 } catch (Exception $e){
    echo $e->getMessage();
 }

1 个答案:

答案 0 :(得分:8)

首先,您遇到语法错误:

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

应该是

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

其次,您不包含ParseQuery

use Parse\ParseQuery;

此外,新的PHP Parse框架会抛出异常。

将代码包装在try catch中。

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

输出现在说什么?