How to operate the database through phonegap
This article mainly introduces how to operate the database through phonegap, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Examples are as follows:
Database Example document.addEventListener ("deviceready", onDeviceReady, false); function onDeviceReady () {var db=window.openDatabase ("Test", "1.0", "Test", 200000); db.transaction (populateDB,errorDB,successDB) } / / initialize database data function populateDB (tx) {tx.executeSql ('DROP TABLE IF EXISTS test1'); tx.executeSql (' CREATE TABLE IF NOT EXISTS test1 (id unique,name)'); tx.executeSql ('INSERT INTO test1 (id,name) VALUES (1, "Tony")) Tx.executeSql ('INSERT INTO test1 (id,name) VALUES (2, "Bill")); tx.executeSql (' INSERT INTO test1 (id,name) VALUES (3, "Tony"));} / / query method function queryDB (tx) {tx.executeSql ('SELECT * FROM test1', [], querySuccess,errorDB) } / / callback for successful query function querySuccess (tx,results) {var len=results.rows.length; var status=document.getElementById ("status"); var string = "Rows:" + len+ "; for (var iTuno Teti