我们可以将Firebase Realtime数据库与核心PHP一起使用吗? [英] Can we use Firebase Realtime database with core PHP?

查看:59
本文介绍了我们可以将Firebase Realtime数据库与核心PHP一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用,后端代码是使用MySql的核心PHP.

I have an Android app and backend code is in core PHP using MySql.

有什么方法可以像我们在MySql上执行的那样直接从API执行CRUD操作吗?

Is there any way to perform CRUD operations from API directly the way we perform on MySql?

如果它是一个Web应用程序,则可以使用javascript来完成,但是我们可以直接从API吗?或者...从Android端开始是最后的选择.

if it was a web app, it could be done it using javascript, but can we directly from API? Or... Doing it from the Android end would is the last option.

推荐答案

要在Android设备上使用Firebase,一定要使用官方的Android SDK

To work with Firebase from an Android device, you should definitely use the official Android SDK https://firebase.google.com/docs/android/setup

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

If you want to execute administrative tasks from a privileged server in PHP, I think you should have a look at https://github.com/kreait/firebase-php - here's a usage example:

<?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();

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

Disclaimer: I am the author of the library :)

这篇关于我们可以将Firebase Realtime数据库与核心PHP一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆