1. 程式人生 > >H5中的web dataBase數據庫

H5中的web dataBase數據庫

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 
 8
9 <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數據庫