H5中的web dataBase數據庫
阿新 • • 發佈:2017-07-07
pda exe html5 style 建數據庫 title nbsp mes row
1.介紹
2.核心方法
3.openDatabase方法
4.transaction方法
5.executeSql方法
6.舉例
7.程序
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>html5-dataBase</title> 6 </head> 7 89 <body> 10 <script type="text/javascript"> 11 var db = window.openDatabase("mydata", "1.0","數據庫描述",20000); 12 //window.openDatabase("數據庫名字", "版本","數據庫描述",數據庫大小); 13 if(db) 14 alert("新建數據庫成功!"); 15 16 db.transaction(function(tx) { 17 tx.executeSql("CREATE TABLE test (id int UNIQUE, mytitle TEXT, timestamp REAL)"); 18 }); 19 20 db.transaction(function(tx) { 21 tx.executeSql("INSERT INTO test (mytitle, timestamp) values(?, ?)", ["WEB Database", new Date().getTime()], null, null); 22 }); 23 24 //db.transaction(function(tx) { 25 // tx.executeSql("DROP TABLE qqs"); 26 //}) 27 28 //db.transaction(function(tx) {29 // tx.executeSql("update test set mytitle=? where mytitle = ‘fsafdsaf‘",[‘xp‘],null,null); 30 //}); 31 32 db.transaction(function(tx) { 33 tx.executeSql("SELECT * FROM test", [], 34 function(tx, result) { 35 for(var i = 0; i < result.rows.length; i++){ 36 document.write(‘<b>‘ + result.rows.item(i)[‘mytitle‘] + ‘</b><br />‘); 37 } 38 }, function(){ 39 alert("error"); 40 }); 41 }); 42 </script> 43 </body> 44 </html>
H5中的web dataBase數據庫