php firebase-realtime-база данных - PullRequest
0 голосов
/ 06 июля 2019

У меня есть скрипт php для подключения php к базе данных реального времени firebase. Я могу успешно запустить скрипт из командной строки, но когда я пробую его из веб-браузера (на моем хосте), он не работает. `

<?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 появился только белый экран.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...