解析PHP SDK没有返回查询结果

时间:2015-04-23 15:12:15

标签: php parse-platform

我能够将Parse PHP SDK(版本1.1.2)安装到我的项目中,并通过快速入门指南成功创建了一个TestObject。但是,当我尝试查询对象时,它什么都不返回。我被困住了,不知道从哪里开始。

use Parse\ParseQuery;

$query = new ParseQuery('TestObject');
$results = $query->find();
foreach($results as $result){
    echo $result->getObjectId() ." - " $result->get("foo") . "\n";
}

1 个答案:

答案 0 :(得分:0)

你可以这样试试:

$myObj= new ParseObject("TestObject");

$myObj->set("objIdd", 1234);
$myObj->set("objName", "My Name");

try {
  $myObj->save();
  echo 'New object created with objectId: ' . $myObj->getObjectId();
} catch (ParseException $ex) { 
  // Execute any logic that should take place if the save fails.
  // error is a ParseException object with an error code and message.
  echo 'Failed to create new object, with error message: ' + $ex->getMessage();
}

//objectId: "XYZABC", objIdd: 1234, objName: "My Name"

$query = new ParseQuery("TestObject");
try {
  $myObj = $query->get("XYZABC");
  // The object was retrieved successfully.
} catch (ParseException $ex) {
  // The object was not retrieved successfully.
  // error is a ParseException with an error code and message.
}

看看这个guide