gpt4 book ai didi

php - 我们可以将 Firebase 实时数据库与核心 PHP 一起使用吗?

转载 作者:可可西里 更新时间:2023-11-01 13:44:39 24 4
gpt4 key购买 nike

我有一个 Android 应用程序,后端代码在使用 MySql 的核心 PHP 中。

有没有办法像我们在 MySql 上执行的那样直接从 API 执行 CRUD 操作?

如果它是一个网络应用程序,它可以使用 javascript 来完成,但我们可以直接从 API 完成吗?或者...从 Android 端进行操作是最后的选择。

最佳答案

要在 Android 设备上使用 Firebase,您绝对应该使用官方 Android SDK https://firebase.google.com/docs/android/setup

如果您想使用 PHP 从特权服务器执行管理任务,我认为您应该看看 https://github.com/kreait/firebase-php - 这是一个用法示例:

<?php

require __DIR__.'/vendor/autoload.php';

use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;

// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');

$firebase = (new Factory)
->withServiceAccount($serviceAccount)
->create();

$database = $firebase->getDatabase();

$newPost = $database
->getReference('blog/posts')
->push([
'title' => 'Post title',
'body' => 'This should probably be longer.'
]);

$newPost->getChild('title')->set('Changed post title');
$newPost->getValue(); // Fetches the data from the realtime database
$newPost->remove();

免责声明:我是图书馆的作者 :)

关于php - 我们可以将 Firebase 实时数据库与核心 PHP 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48924175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com