Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can PHP retrieve data from Firebase / Firestore?

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

like image 796
crbon Avatar asked Mar 11 '18 23:03

crbon


People also ask

Can PHP work with Firebase?

Q: Can I use Firebase with PHP? A: Yes, Firebase provides a comprehensive API for integrating the platform with your PHP projects.


2 Answers

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.

like image 192
Dan McGrath Avatar answered Oct 03 '22 18:10

Dan McGrath


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

like image 39
Peter Haddad Avatar answered Oct 01 '22 18:10

Peter Haddad