Basic use process of websql

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.