我有一个用于将php连接到firebase实时数据库的php脚本。我可以从命令行成功运行该脚本,但是当我从Web浏览器(在我的主机上)尝试运行该脚本时,它无法正常工作。 `
<?php
require_once ('./vendor/autoload.php');
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
class Users{
protected $database;
protected $dbname = 'users';
public function __construct(){
$acc = ServiceAccount::fromJsonFile(__DIR__ . '/my_json_file');
$firebase = (new Factory)->withServiceAccount($acc)->create();
$this->database = $firebase->getDatabase();
}
public function get(int $userID = NULL){
if (empty($userID) || !isset($userID)) { return FALSE; }
if($this->database->getReference($this->dbname)->getSnapshot()->hasChild($userID)){
return $this->database->getReference($this->dbname)->getChild($userID)->getValue();
} else {
return FALSE;
}
}
public function insert(array $data) {
if (empty($data) || !isset($data)) { return FALSE; }
foreach ($data as $key => $value){
$this->database->getReference()->getChild($this->dbname)->getChild($key)->set($value);
}
return TRUE;
}
public function delete(int $userID) {
if (empty($userID) || !isset($userID)) { return FALSE; }
if ($this->database->getReference($this->dbname)->getSnapshot()->hasChild($userID)){
$this->database->getReference($this->dbname)->getChild($userID)->remove();
return TRUE;
} else {
return FALSE;
}
}
}
$users = new Users();
var_dump($users->insert([
'name' => 'Harry',
]));
` 我正在使用phpstorm。 当我在终端输出上运行“ php Users.php”时,输出为“ bool(true)”,但是当上载ftp并在http://mydomain/Firebase_php_NurSedaGuler/Users.php上运行时,只是白屏显示。