HTML5 Web SQL

HTML5 Web SQL database


The Web SQL Database API is not part of the HTML5 specification, but it is a stand-alone specification that introduces a set of APIs that use SQL to manipulate client databases.

If you are a web backend programmer, it should be easy to understand the operation of SQL.

You can also refer to our SQL tutorial for more knowledge of database operations.

Web SQL databases work in the latest versions of Safari, Chrome, and Opera browsers.

Core method

The following are the three core methods defined in the specification:

openDatabase : This method creates a database object using an existing database or a new database.

Transaction : This method allows us to control a transaction and perform commit or rollback based on this.

executeSql : This method is used to execute the actual SQL query.

Open the database

We can use the openDatabase() method to open an existing database. If the database does not exist, we will create a new database with the following code:


The five parameter descriptions corresponding to the openDatabase() method:

Name database

version number

Description text

Database size

Create callback

The fifth parameter, the create callback, is called after the database is created.

Perform a query operation

Execute the operation using the database.transaction() function:


After the above statement is executed, a table named LOGS is created in the 'mydb' database.

Insert data
After executing the above table creation statement, we can insert some data:


We can also use dynamic values ​​to insert data:

The e_id and e_log in the instance are external variables, and executeSql maps each entry in the array parameter to "?".

Read data
The following example demonstrates how to read data that already exists in the database:


Full instance

 

Delete Record

The format used to delete records is as follows:

Deleting the specified data id can also be dynamic:

Update record
The format used to update records is as follows:


Updating the specified data id can also be dynamic:


Update record
The format used to update records is as follows:


Updating the specified data id can also be dynamic:


Full instance

 



Last Updated: 2018-07-06 12:32:44 By akshay

SHARE THIS

share_facebook share_twitter share_google_plus

Please Comment Here :