如何在PhoneGap App中实现数据库? [英] How to implement database in PhoneGap App ?

查看:93
本文介绍了如何在PhoneGap App中实现数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的,我试图构建一个应用程序,要部署与PhoneGap,Android和iOS。
我想知道如何链接到将存储时间表数据的数据库。



我的问题是如何包括数据库,以便它可以与PhoneGap打包。



我查看了PhoneGap文档,他们对我来说,如何设置/创建数据库并不真实。






更新:
本网站显示本地存储的一些信息,但是当我把它放在加载图像上。 >

任何进一步的想法?



请参考下面的链接,使用Sq-lite的简单操作,也可以从上面 link



使用Sq-lite的简单操作:
http://www.raymondcamden.com/index.cfm/2011/10 / 20 / Example-of-PhoneGaps-数据库支持



在2013年5月8日修改,固定2016年1月19日 p>

使用DB的基本操作:

 < script type =text / javascriptcharset =utf-8src =cordova-xxxjs>< / script> 
< script type =text / javascriptcharset =utf-8>
//等待Cordova加载
document.addEventListener(deviceready,onDeviceReady,false);

// Cordova准备好
函数onDeviceReady(){
var db = window.openDatabase(Database,1.0,Cordova Demo,200000);
db.transaction(populateDB,errorCB,successCB);
}

//填充数据库
函数populateDB(tx){
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO(id unique,data)');
tx.executeSql('INSERT INTO DEMO(id,data)VALUES(1,First row)');
tx.executeSql('INSERT INTO DEMO(id,data)VALUES(2,Second row)');
}

//事务错误回调
function errorCB(err){
alert(Error processing SQL:+ err);
}

//事务成功回调
function successCB(){
alert(success!
}
< / script>

refrence



您可以在File explorer中检查数据库



在ADT包
窗口>>显示视图>>文件资源管理器


I'm new to this, and I am trying to build an app to be deployed with PhoneGap, to both Android and iOS. I am wondering how to link to a database which will store timetable data.

My question is how to include the database so it can be packaged with PhoneGap.

I have looked at the PhoneGap docs, and they don't really make sense to me as to how to set up/create the database


Update: This website shows some info on local storage, but when i put it in, hangs on the loading image.

Any further ideas?

http://www.aquim.com/web-article-237.html

解决方案

Please refer below link for simple operation with Sq-lite.and also you can get basic idea of Storage API from above link.

Simple operation with Sq-lite : http://www.raymondcamden.com/index.cfm/2011/10/20/Example-of-PhoneGaps-Database-Support

Edited on 8th MAY 2013 and fixed 19th January 2016

Basic operation with DB :

<script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
function onDeviceReady() {
    var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
    db.transaction(populateDB, errorCB, successCB);
}

// Populate the database 
function populateDB(tx) {
    tx.executeSql('DROP TABLE IF EXISTS DEMO');
    tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}

// Transaction error callback
function errorCB(err) {
    alert("Error processing SQL: " + err);
}

// Transaction success callback
function successCB() {
    alert("success!");
}
</script>

refrence

You can check Data base in File explorer

In ADT bundle Window>>show view>> File Explorer

这篇关于如何在PhoneGap App中实现数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆