Portal Integrators

Firebase Database CRUD

AdobeStock_55187359

AdobeStock_55187359

Firebase Database CRUD

by

Fresh from graduating from college, I only knew two types of database, MySQL, and MS Access but when I started working, I heard a database that I don’t know how to use, and it is called Firebase.

Firebase is a hierarchical database, unlike MySQL that is a relational database. Hierarchical means that the form of saving data is in JSON tree. Before I always use MySQL as the database for the websites or apps I am making, so for me to learn new concept much easier, I compared the two database approaches.

Comparative approach to learning Firebase applied to the websites

In Firebase, when you create a project, the creation of database will be included in it, the project id will be the name of the database, and in MySQL, you are the one who will give the name to the database specifically.

 

 

 

After creating the database, you need to connect this to your website. In Firebase approach, the usual server is in JavaScript unlike MySQL; it often uses PHP as a server. To add Firebase database to your codes, you need to configure it first, as if you are selecting database in MySQL, the code “mysqli_connect(server, username,password,database_name)”. You can find the SDK configuration in //console.firebase.google.com/project//overview and click on the “Add Firebase to your web app” then paste it into your code.

If you want to retrieve data, you need to use the code, “database.ref(node_directory)” just like the code “Select * from table_name” in MySQL. The node directory is the words after https://project_id.firebaseio.com/ in your URL. The good thing about Firebase is it can transmit new data concurrently while the application is running. These codes are called “child_changed” which will be loaded when there is an update on the indicated node directory and “child_added” which will be loaded when the new node has been added on the pointed node directory.

 

 

 

Inserting data in Firebase is “database.ref(node_directory).set({node_name : value})” while in MySQL, it is “Insert into table_name (field_name) values (value)” .

When you need to update data in Firebase, the code “database.ref().update({node_name : value})” is used similarly to the code in MySQL, “Update
set field_name=value where field_name=value”.

Lastly, Firebase uses the code “database.ref(node_directory).remove()” in order for the data to be deleted, which is the same as the code used in MySQL, “Delete from table_name where field_name=value”.
The update and delete in Firebase doesn’t need the where clause because the node directory must be correctly pointed to the location of the node to be updated or deleted.

Send us your questions on Firebase

10 + 2 =

Related Blog Post

What is Ajax?

Ajax and javascript are great for creating dynamic web applications, but before we discuss the AJAX let us first talk about how the browser works. The browser gets information to display a page. How does it work? When a browser request a page from the website the...

Microsoft Azure

Today we are living in the internet era or what commonly known as “Information age.” A lot of technology invented rapidly, like chatbot, web application like Facebook, Twitter, Instagram, and Snapshot, etc., but have you ever think that how did you access these kind...

The Never Endless Bug

Bug? If you are an ordinary person the one inlet in your mind about a bug is like a pesky worm or virus, but no, as a developer in our daily working experience we always encounter different bugs. That was super annoying but we have no choice because debugging is a...

Exit mobile version