I have an Android app and backend code is in core PHP using MySql.
Is there any way to perform CRUD operations from API directly the way we perform on MySql?
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.
To work with Firebase from an Android device, you should definitely use the official Android SDK https://firebase.google.com/docs/android/setup
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With