1. Create or open a database (OpenDatabase)
var db = OpenDatabase (' dbname ', ' 1.0 ', ' discription ', 2 * 1024); Currently testing is only supported by Chrome browser
Opendatabasek Five parameters are: database name, version number, description, database size, create callback function. The callback function is an optional parameter.
2. Execute SQL statements
Db.transaction (function(TX) {Tx.executesql (' CREATE TABLE IF not EXISTS T1 (id unique, log) ', [],function(TX, result) {},function(TX, error) {Console.log (' Create table T1 error: ' +error.message); }); Tx.executesql (' INSERT into T1 (ID, log) VALUES (?,?) ', [4, ' bags '],function(TX, result) {Console.log (' Rows affacted: ' +result.rowsaffected); }, function(TX, error) {Console.log (' Error: ' +error.message); }); });
The ExecuteSQL function parameters are: 1. The SQL statement to execute; the placeholder substitution (array) in the 2.SQL statement; 3. Execute a successful callback function; 4. Execute the failed callback function;
3. Working with query results
Db.transaction (function (TX) { tx.executesql (function(TX, result) { var // Number of records queried for (var i = 0; i < length; i++) { Console.log (Result.rows.item (i)); } function (TX, error) { console.log (' qruey table T1 error: ' + error.message); });
Basic use process of websql