Can PHP retrieve data from Firebase / Firestore?

若如初见. 提交于 2019-12-06 04:34:01

问题


Is there a PHP library for connecting php to the Firebase Firestore database? Is it even possible to PHP to retrieve data from Firebase?


回答1:


Yes, there is now a 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());
}

You'll find more examples in our documentation now, just select the PHP tab on the snippets.




回答2:


Yes, you can retrieve data using PHP, an example:

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

The above will order the reference's children by the values in the field 'height' in ascending order.

more info here:

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

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



来源:https://stackoverflow.com/questions/49226283/can-php-retrieve-data-from-firebase-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!