(2) HTML5 and html5
Introduction
Web SQL Database is the local SQLite Database. The method and method are basically the same as those of SQLite.
Determine whether the browser supports
if (!window.openDatabase) { alert('Databases are not supported in this browser.'); }
OpenDatabase
Open or create a database. The openDatabase method uses an existing database or creates a new database to create a database object.
OpenDatabase (DbName, DBVersion, DBDescribe, DBSize, Callback ());
1 db=openDatabase('Student','1.0','StuManage',2*1024*1024,function(){2 console.log('create db success');3 });
Transaction executes transaction processing through the transaction method in the database object. Each transaction processing request is used as an independent database operation, which effectively avoids conflicts during data processing. Syntax: transaction (TransCallback, ErrorCallback, SuccessCallback); execute SQL
1 db.transaction(function(tx) { 2 tx.executeSql("CREATE TABLE IF NOT EXISTS test (id int UNIQUE, title TEXT, content TEXT)"); 3 });
Execute real SQL queries.
ExecuteSql (strSQL, [arguments], SuccessCallback, ErrorCallback); parameters are the statements to be executed, the required real parameters, the success callback function, and the Failure callback function.
// Create a data Table test db. transaction (function (tx) {tx.exe cuteSql ("create table if not exists test (id int UNIQUE, title TEXT, content TEXT)") ;}); // execute add db. transaction (function (tx) {tx.exe cuteSql ("create table test (id, title)"); tx.exe cuteSql ("insert into test values (1, 'ali1 ')"); tx.exe cuteSql ("insert into test values (2, 'ali2', 'test')") ;}); // execute the query database. transaction (function (tx) {tx.exe cuteSql ("select * from test", [], function (tx, result) {for (var I = 0; I <result. rows. length; I ++) {var testObj = result. rows. item (I); alert (testObj. id + "------" + testObj. title );}});});