Issue
I'm trying to use php with firebase, but I have this error when I'm trying to run the code.
Fatal error: Uncaught Error: Call to undefined method Kreait\Firebase\Factory::getDatabase() in C:\xampp\htdocs\table\includes\db.php on line 10
the db.php file:
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$firebase = (new Factory())->withServiceAccount(__DIR__.'/bib-bayitback-firebase-adminsdk-lkch9-44e22401ec.json');
$database = $firebase->getDatabase();
?>
my composer.json file:
{
"require": {
"kreait/firebase-php": "5.0"
}
}
how can I solve it?
Solution
You have installed v5.0.0 of the Firebase Admin SDK for PHP, but the tutorial you followed is for a 4.x version.
This is an issue that happens so often that it has its own section in the "Troubleshooting" section in the SDK's documentation.
With v5.x, the correct way to initialize a Firebase component is:
$factory = (new Factory())->withServiceAccount(__DIR__.'/bib-bayitback-firebase-adminsdk-lkch9-44e22401ec.json');
$database = $factory->createDatabase();
As a side note:
{
"require": {
"kreait/firebase-php": "5.0"
}
}
will install version 5.0 and 5.0. only (the current version is 5.13). You will never receive a newer release of the library because you fixed the version constraint to 5.0
.
If you want to be sure to receive new features and bug fixes for the SDK, please add a caret(^
) in front of the version number:
{
"require": {
"kreait/firebase-php": "^5.0"
}
}
This will allow your project to receive the latest 5.x release of the SDK.
Answered By - jeromegamez
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.