【问题标题】:Can PHP retrieve data from Firebase / Firestore?PHP 可以从 Firebase / Firestore 检索数据吗?
【发布时间】:2018-08-19 22:40:51
【问题描述】:

是否有用于将 php 连接到 Firebase Firestore 数据库的 PHP 库? PHP 甚至可以从 Firebase 中检索数据吗?

【问题讨论】:

  • @PeterHaddad 是的,我认为这就是我所需要的。我很快就会更详细地看一下
  • @Kato 我已经开始使用 Firestore 数据库了。我可以使用 PHP 进行电子邮件和密码验证吗?如果没有,可以用 PHP 检索文档数据吗?到目前为止,我所看到的一切都指向否定,但不知何故,我仍然希望有办法。

标签: php firebase firebase-authentication google-cloud-firestore


【解决方案1】:

是的,现在有一个PHP client library

use Google\Cloud\Firestore\FirestoreClient;

$db = new FirestoreClient();

$citiesRef = $db->collection('cities');
$query = $citiesRef->where('state', '=', 'CA');
$snapshot = $query->documents();
foreach ($snapshot as $document) {
    printf('Document %s returned by query state=CA' . PHP_EOL, $document->id());
}

您现在可以在我们的documentation 中找到更多示例,只需选择 sn-ps 上的 PHP 选项卡。

【讨论】:

  • 但是如何在网页中显示每个值,即。 html
【解决方案2】:

是的,您可以使用 PHP 检索数据,例如:

$db->getReference('people')
->orderByChild('height')
->getSnapshot();

上面将按字段“height”中的值升序排列引用的子项。

更多信息在这里:

http://firebase-php.readthedocs.io/en/latest/realtime-database.html

https://github.com/kreait/firebase-php

【讨论】:

  • 这都与实时数据库相关,而不是 Cloud Firestore,这是我所追求的(因为它与现有的 Cloud Firestore 项目有关)
猜你喜欢
  • 1970-01-01
  • 2023-03-09
  • 2021-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多