首页 文章

如何使用PhoneGap在内部数据库中读写?

提问于
浏览
2

我在 "Assets" 文件夹下有一个内部SQLite DB,其中我存储了100个用户名和相应的密码,如何通过phoneGap访问它 .
我读过了

我仍然无法弄清楚如何连接到已经创建的内部数据库,
dbname = userauth Tablename = reg parameters = usrnm , psw
任何答案都非常鼓励

Am using this here .

Login Screen

2 回答

  • 1
    /**
     * Creates / Opens a connection to DB
     */
    DB.openDB = function() {
        try {
            if (!window.openDatabase) {
                //alert('Cannot open database!');
            } else {
                var shortName = 'db_name';
                var version = '1.0';
                var displayName = 'DBNAME';
                var maxSize = (DEVICE_TYPE == DEVICE_ANDROID || DEVICE_TYPE == DEVICE_ANDROID_TAB) ? 5242880 : 1000000; ////819200; //65536; // in bytes // increased to support Android//163840; // 
                this.vocabDB = window.openDatabase(shortName, version, displayName, maxSize, this.DBCreated);
                this.DBSupported = true;
            }
        } catch(e) {
            //console.log("DB Error handling code goes here.");
            //console.log(e);
            return;
        }
    }
    
  • 2

    那么,您可以将window.openDatabase()创建到assets文件夹中的数据库 . 您需要将其复制到正确的位置,以便WebView加载它 . 看看这个:

    [http://gauravstomar.blogspot.ca/2011/08/prepopulate-sqlite-in-phonegap.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+GauravSTomarBootstrappingIntelligence+(Gaurav+S+Tomar+:+Bootstrapping+Intelligence](http://gauravstomar.blogspot.ca/2011/08/prepopulate-sqlite-in-phonegap.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+GauravSTomarBootstrappingIntelligence+(Gaurav+S+Tomar+:+Bootstrapping+Intelligence))

    发布,因为Gaurav为您提供了在Android和iOS上执行此操作的代码 .

相关问题