Script is disabled Firebase Database CRUD | Portal Integrators
Select Page

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

11 + 6 =

Related Blog Post

Hand Coding: The Web Developers’ Superpowers!

These days a lot of website builders and content management systems are available online. Creating stunning websites without knowing how to write a code is just a snap, easy as 123 and ABC, even a 12-year-old can learn it. Using this tools allows you to drag and drop...

Why Backup is Important to your WordPress Site

Building a website on Wordpress is easy even ordinary people or not a professional web developer can create a simple web page. For me, as entry-level web developer WordPress is a good practice to become a successful web developer in the future. Word press is easy,...

Web Developer from Scratch

I learned web designing during college, using HTML, CSS, and JavaScript. But getting into the field of web development made me realize that there is more to it. Learning to develop a properly functioning website is not an easy task and can be quite confusing at times....