Android 英特尔 XDK:将您的移动应用连接到数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22828109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Intel XDK: Connecting your mobile app to a database
提问by Ng'esh
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.
提前致谢。
回答by Iman Sedighi
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
1- 使用 HTML5 客户端数据库。HTML5 在本地客户端机器上提供四种不同类型的数据存储。他们是
Local Storage. Web SQL Storage. Session Storage Indexed DB
本地存储。Web SQL 存储。会话存储索引数据库
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
这取决于您的需求,您可以使用其中之一。如果您需要一个持久性数据库来保存小于 5 Mb 的值,我建议您使用 LocalStorage,因为它的实现非常简单。即使在手机关机或重置的情况下,您保存在 HTML5 localstorage 中的数据也不会被删除。只有当你通过 localStorage.removeItem() 删除数据时,数据才会被删除;如果您有大量数据或需要一个中央数据库,则不建议使用客户端数据库,您应该向世界上使用此应用程序的每个人展示该数据库。在这些情况下它更好,您使用服务器端数据库
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
您可以在 XDK 网站上阅读一篇关于如何使用 html5 本地数据库的非常好的文章: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.
2-您可以使用服务器数据库,如 MySQL 或 SQL 服务器。但是,您需要通过 AJAX 将 html 代码连接到服务器中的 PHP 或 asp.net 脚本。您可以使用 JSON 将数据从服务器端的 PHP 传输到客户端的 JS。
3- You can use cloud databases like Parse.com however Parse.com will be fully retired on January 28, 2017.
3- 您可以使用 Parse.com 等云数据库,但 Parse.com 将于 2017 年 1 月 28 日完全停用。
回答by mnementh
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/.
对于 Web 或混合应用程序的本地存储,您可以使用 IndexedDB。有一个关于 HTML5 岩石的很棒的教程,你可以按照: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.
对于远程数据库,我喜欢使用 Parse.com 来存储数据对象,例如我存储用户设置、高分等的游戏。https://parse.com/docs/rest。看看他们的快速入门指南。
Hope that helps!
希望有帮助!
回答by Sandeep Gantait
You could use LOCAL STORAGE the usage is pretty easy:
您可以使用 LOCAL STORAGE 用法非常简单:
/* 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.
就是这样,确保您的数据不超过 5 MB。