如何从php连接firebase?
您好,我正在尝试从php连接到firebase数据库,我有以下代码如何从php连接firebase?,php,firebase,Php,Firebase,您好,我正在尝试从php连接到firebase数据库,我有以下代码 <?php require __DIR__.'/vendor/autoload.php'; use Kreait\Firebase\Factory; use Kreait\Firebase\ServiceAccount; $serviceAccount = ServiceAccount::fromJsonFile(__DIR__ . '/secret/sajilo-entrance-med-firebase-admin
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__ . '/secret/sajilo-entrance-med-firebase-adminsdk-1bta4-487ebfe276.json');
$factory = (new Factory)->withServiceAccount($serviceAccount);
$firebase = (new Factory)
->withServiceAccount('$serviceAccount')
->withDatabaseUri('https://sajilo-entrance-med.firebaseio.com/')
->create();
$database = $firebase->getDatabase();
?>
我得到了这个错误
致命错误:未捕获的TypeError:传递给Kreait\Firebase\Factory::withServiceAccount()的参数1必须是Kreait\Firebase\ServiceAccount的实例,给定字符串,在第10行的C:\xampp\htdocs\medEntry\dbconfig.php中调用,并在C:\xampp\htdocs\medEntry\vendor\kreait\firebase php\src\firebase\Factory.php中定义。php:77堆栈跟踪:#0 C:\xampp\htdocs\medEntry\dbconfig.php(10):kreait\firebase\Factory->with-withServiceAccount('$serviceCount')#1 C:\xampp\htdocs\medEntry\插入测试.php(43):包括(C:\xampp\htdocs…)#2{main}在第77行的C:\xampp\htdocs\medEntry\vendor\kreait\firebase php\src\firebase\Factory.php中抛出
尝试将
使用serviceAccount(“$serviceAccount”)
更改为使用serviceAccount($serviceAccount)
是否检查了$serviceAccount
包含的内容?它似乎是一个字符串,而工厂::使用serviceAccount()
需要一个serviceAccount
类的实例。