Firebaseのrealtime databaseを使ってみる

$ curl -sS https://getcomposer.org/installer | php
// composer動作確認
$ php composer.phar
$ php composer.phar require ktamas77/firebase-php

$ sudo apt-get install php7.4-curl
$ php -v

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require_once "vendor/autoload.php";
 
define("DEFAULT_URL","https://*-default-rtdb.firebaseio.com");
define("DEFAULT_TOKEN","");
 
$test = array(
    "name" => "Polkadot",
    "code" => "DOT"
);
 
$firebase = new \Firebase\FirebaseLib(DEFAULT_URL,DEFAULT_TOKEN);
 
$firebase->set("/users",$test);
 
$user = $firebase->get("/users");
 
echo $user;

$ php test.php
{“code”:”DOT”,”name”:”Polkadot”}

おおおおお、なんか感動した!