Intel XDK: Connecting your mobile app to a databas

2019-04-30 04:32发布

问题:

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.

回答1:

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.



回答2:

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!



回答3:

You could use LOCAL STORAGE the usage is pretty easy:

/* saving the data in Local Storage */
//yourData : this data could be an array, object or a plain string
window.localStorage.setItem('data', JSON.stringify(yourData));

/*  retriving the data from local storage */
window.localStorage.getItem('data');

That's all, make sure your data doesn't exceed 5 MB.