2015-02-08 43 views
0

這不可能是一個正確的問題要問在這裏,但我有點困惑如何&與使用的數據庫我phonegap application (made with HTML5 + Javascript+CSS) 如果有任何引用鏈接或」與PhoneGap的應用程序使用的數據庫

任何想法,任何人
How I can use database in this application? 

在此先感謝。

+0

使用sqlite或基於服務器的,這可以是任何事情。 – dandavis 2015-02-08 02:28:28

+0

@dandavis任何鏈接僅供參考? – Rahul 2015-02-08 02:51:47

+0

google.com/?q=codova%20db? – dandavis 2015-02-08 02:57:58

回答

0

您可以使用SQLite包裝。

Plugin Link

這是非常容易使用。

// Wait for Cordova to load 
document.addEventListener("deviceready", onDeviceReady, false); 

// Cordova is ready 
function onDeviceReady() { 
    var db = window.sqlitePlugin.openDatabase({name: "my.db"}); 

    db.transaction(function(tx) { 
    tx.executeSql('DROP TABLE IF EXISTS test_table'); 
    tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)'); 

    // demonstrate PRAGMA: 
    db.executeSql("pragma table_info (test_table);", [], function(res) { 
     console.log("PRAGMA res: " + JSON.stringify(res)); 
    }); 

    tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) { 
     console.log("insertId: " + res.insertId + " -- probably 1"); 
     console.log("rowsAffected: " + res.rowsAffected + " -- should be 1"); 

     db.transaction(function(tx) { 
     tx.executeSql("select count(id) as cnt from test_table;", [], function(tx, res) { 
      console.log("res.rows.length: " + res.rows.length + " -- should be 1"); 
      console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1"); 
     }); 
     }); 

    }, function(e) { 
     console.log("ERROR: " + e.message); 
    }); 
    }); 
} 

鏈接中提供了詳細的文檔。

如果您需要小數據來保存少量字,那麼您可以使用localStorage。

+0

如何爲瀏覽器平臺應用程序安裝SQLite插件? – Rahul 2015-02-09 05:16:44

+0

它支持ios,android,wp – AtanuCSE 2015-02-09 05:25:36

相關問題