PHP Firebase CRUD

In this tutorial I have explain how develop PHP Firebase CRUD Example projects. Actually Google Firebase provides more features when compared to other database like MySQL, MongoDB etc. First understand the basic things, Firebase not a Structure Query Language.

Firebase is a NoSQL cloud hosted database that store data in real time. It’s back-end application & mostly used for developing both of web & mobile applications. Major advantage is we can directly hook their GUI, because it’s ready-made back-end system.

Generally MongoDB is a No Structured Query Language & Firebase also NoSQL. But Firebase perfect for small application like not able to load high level traffics. On the other hand via MongoDB helps to build large scalable application.

Through the Angular & Firebase combination we can able to develop perfect web application. Because both was developed by Google company.

How to Start with Firebase ?

  1. First Install CLI
  2. Connect your local project
  3. Connect the both server (client & server)

For more read the official documentation.

If you are Android Developer ? or plan to move on the section ? Firebase is the best options. We can able to develop more projects with the help of google services.

Objective

Okay let’s start how implement the CRUD (Create Read Delete Update) concepts using Firebase. However this is major concept for developing all modules. Because without skipping this we can’t able to develop further projects. In every projects we need create or delete options to take out the systems on next level.

php firebase crud

I hope above screenshot helps to understand the projects. If you have any doubts regarding this just comment below I will try to solve your errors within a hour.

Authentication

I hope already you know what is Firebase authentication, because most of students have no knowledge in the particular domain. It’s provide back-end services, User Interface, Library Files etc. Before working any concept just learn about the thing then only you get clear idea about the subject.


<?php
session_start();
include "dbcon.php";

// Proses Hapus data Firebase
if (isset($_POST['hapus_data'])) 
{
    $id = $_POST['id_key'];
    // echo $id;
    $ref_table = "mahasiswa/".$id;
    $hapusdata = $database->getReference($ref_table)->remove();
    if ($hapusdata) {
        $_SESSION['status'] = "data berhasil di hapus";
        header("location:index.php");
    }else{
        $_SESSION['status'] = "data gagal di dihapus";
        header("location:index.php");
    }
}

// Proses Update/Edit Data firebase
if(isset($_POST['update_data']))
{
    $id = $_POST['id'];
    $nama = $_POST['nama'];
    $nim = $_POST['nim'];
    $email = $_POST['email'];
    $alamat = $_POST['alamat'];   

    $updatedata = [
        'nama' => $nama,
        'nim' => $nim,
        'email' => $email,
        'alamat' => $alamat
    ];
    $ref_table = "mahasiswa/".$id;
    $queryupdatae = $database->getReference($ref_table)->update($updatedata);

    if ($queryupdatae) {
        $_SESSION['status'] = "data berhasil di Update";
        header("location:index.php");
    }else{
        $_SESSION['status'] = "data gagal di update";
        header("location:index.php");
    }
   
}

// Proses Input data Firebase
if (isset($_POST['submit'])) 
{
    $nama = $_POST['nama'];
    $nim = $_POST['nim'];
    $email = $_POST['email'];
    $alamat = $_POST['alamat'];   

    $postData = [
        'nama' => $nama,
        'nim' => $nim,
        'email' => $email,
        'alamat' => $alamat
    ];

    $ref_table = "mahasiswa";
    $postRef = $database->getReference($ref_table)->push($postData);

    if ($postRef) {
        $_SESSION['status'] = "data berhasil di simpan";
        header("location:add.php");
    }else{
        $_SESSION['status'] = "data gagal di simpan";
        header("location:index.php");
    }

}
?>

Above section explained only the authentication process. For more read Firebase authentication initialization methods.

When compared to MySQL, Firebase is very comfortable & easy to use the projects. The selection based on your client requirements like scalability, maintenance, structure etc. Already I told MySQL is the best choice for large capable system.

Also Read – C Sharp Projects

PHP Firebase CRUD Code

Above all explanation helps to build this project using Firebase technology. Suppose if you are beginner on this sector don’t worry & never give up. Becuase beginning is always hardest part to understand the basic difficulties. After working on few months, you are the master in the particular area.

Leave a Reply