我是Parse的新手,我来自mysql。在 mysql 中,可以在数据库宽度 $db->lastInsertId(( 中插入最后一个 id。我不知道如何使用 Parse db 做到这一点,你能帮我吗?
如何在解析数据库中获取最后一个插入 id?
谢谢
使用Parse PHP SDK,一切都是基于对象的。这意味着,当您在 Parse 存储中创建并保存 Parse 对象时,可以使用 ParseObject
的 getObjectId()
方法在保存后检索对象 ID:
$gameScore = new ParseObject("GameScore");
$gameScore->set("score", 1337);
$gameScore->set("playerName", "Sean Plott");
$gameScore->set("cheatMode", false);
try {
$gameScore->save();
echo 'New object created with objectId: ' . $gameScore->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();
}
从上面的例子中,我们使用的值得注意的方法是 $gameScore->getObjectId()
.相应的输出将是:
使用 objectId 创建的新对象:xWMyZ4YEGZ
这与 lastInsertId()
方法不同,因为从 getObjectId()
获得的值在保存到 Parse 云后对于特定对象将始终相同。