【发布时间】:2020-12-06 07:57:38
【问题描述】:
我正在使用这个 firebase PHP 库
https://github.com/kreait/firebase-php
我必须通过 user 表中的键过滤数据。
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__ . self::SECRET_FILE);
$firebase = (new Factory)
->withServiceAccount($serviceAccount)
->withDatabaseUri(self::DATABASE_URL)
->create();
$database = $firebase->getDatabase();
$userIds = ['xpCjiz6cuGSx4oBrEUIsn8cqxPy2','xpdXbPu3HdfQ48eZhk2wjUTJtq43','XpdxeLmlvhVABkBYDFyfcVI52Xa2'];
forreach($userIds as $userId){
$values = $database->getReference('users/'.$userId)
->getValue();
echo "<pre>";
print_r($values);
}
我有用户 ID 列表并根据随机键获取所有用户记录,那么如何在一个请求中获取所有数据?
我上面的代码可以很好地获取所有用户数据,但问题是我必须根据键发送多个请求。例如,如果我有 15 个userids,那么我必须向 firebase 数据库请求 15 次以获取用户数据。
这里的 $userId 是在 firebase 表的每一行中创建的随机值。
如何通过过滤多个键在一个请求中获取所有用户数据?
【问题讨论】:
标签: php firebase firebase-realtime-database filter