This paper is the official HTML5 training course for Brother Lian it education organization, mainly introduces: HTML5 Mobile Development Road (a)--HTML5 Web SQL Database
I. Introduction of WEB Database
 
websql database API is not actually part of the HTML5 specification, but a separate specification. It manipulates the client's database through a set of APIs. Safari, Chrome, Firefox, opera and other mainstream browsers have supported Websql database
websql databases have three core methods:
1) Open the Database OpenDatabase () method:
2) transaction Transaction () method:
3) Execute SQL command ExecuteSQL () method:
Second, WEB database operation use
1) Open the Database OpenDatabase () method:
This method creates a database object that can either use an existing database or create a new database.
2) transaction transaction () method:
This method can be used to control transactions, perform commit operations, or rollback operations.
3) Execute SQL command ExecuteSQL () method:
This method is used to execute SQL queries.
Third, examples
[HTML] View plain copy
<!DOCTYPE HTML>
<html>
<head>
<meta charset="urf-8"/>
</head>
<body>
<script type="text/javascript">
/ / Create a database
Var db = window.openDatabase("dawanganban", "1.0","Database Description", 20000);
/ / Create a data table
Db.transaction(function(tx) {
tx.executeSql("CREATE TABLE test (id int UNIQUE, mytitle TEXT, timestamp REAL)");
});
/ / Insert data
Db.transaction(function(tx) {
tx.executeSql("INSERT INTO test (id, mytitle, timestamp) values(?, ?, ?)", [1, "WEB Database", new Date().getTime()], null, null);
});
/ / Insert data
Db.transaction(function(tx) {
tx.executeSql("INSERT INTO test (id, mytitle, timestamp) values(?, ?, ?)", [2, "DaWanGanBan", new Date().getTime()], null, null);
});
//delete data
/*
Db.transaction(function(tx){
tx.executeSql("DELETE FROM test where mytitle=?",["WEB Database"],null,null);
});
*/
//db.transaction(function(tx) {
// tx.executeSql("DROP TABLE qqs");
//})
//db.transaction(function(tx) {
// tx.executeSql("update test set mytitle=? where mytitle = ‘fsafdsaf‘",[‘xp‘],null,null);
//});
//Query data
Db.transaction(function(tx) {
tx.executeSql("SELECT * FROM test", [],
Function(tx, result) {
For(var i = 0; i < result.rows.length; i++){
Document.write(‘<b>‘ + result.rows.item(i)[‘mytitle‘] + ‘</b><br />’);
}
}, function(){
Alert("error");
});
});
</script>
</body>
</html>
HTML5 Mobile Development Road (--HTML5) Web SQL Database