Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intel XDK: Connecting your mobile app to a database

I am currently developing an application which if I don't have a database, the application after building will be heavy. How do I connect the application to a database, either local or remote?

Thanks in advance.

like image 533
Ng'esh Avatar asked Apr 03 '14 04:04

Ng'esh


2 Answers

You can use one of the following methods for using database:

1- Using HTML5 client side databases. HTML5 provides four different types of Storage of data on a local client's machine. They are

Local Storage. Web SQL Storage. Session Storage Indexed DB

It depends on your demands you can use one of them. If you need a persistent database for saving values less than 5 Mb, I recommend you LocalStorage as implementation of that is very easy. The data you saved in HTML5 localstorage will not be deleted even in case of phone shut down or reset. The data will be deleted only when you remove it by localStorage.removeItem(); Client side database is not recommended if you have huge amount of data or you need a central database which you should show to everybody who use this app in the world. in these cases its better, you use server side database

You can read a very nice article about how to use html5 local databases in XDK website: https://software.intel.com/en-us/articles/html5-local-storage

2- You can use server database like MySQL or SQL server. however you need to connect your html codes to a PHP or asp.net script in a server by AJAX. You may use JSON for transfer data from PHP in server side to JS in the client side.

3- You can use cloud databases like Parse.com however Parse.com will be fully retired on January 28, 2017.

like image 55
Iman Sedighi Avatar answered Sep 28 '22 00:09

Iman Sedighi


For local storage of a web or hybrid app you can use IndexedDB. There's a great tutorial on HTML5 rocks for a TODO list that you can follow: http://www.html5rocks.com/en/tutorials/indexeddb/todo/.

For remote databases, I like to use Parse.com to store data objects like for games I store user settings, high scores, etc. https://parse.com/docs/rest. Take a look at their Quickstart guide.

Hope that helps!

like image 27
mnementh Avatar answered Sep 27 '22 23:09

mnementh