Get the App
SLTechnology News&Howtos  ›  Development  › 

How to connect to the database in HTML5

Shulou Source: shulou.com Published: 2022-06-02 01:04:28 10月19日 Update

In this article Xiaobian for you to introduce in detail "how to connect to the database in HTML5", the content is detailed, the steps are clear, the details are handled properly, I hope this article "how to connect to the database in HTML5" can help you solve your doubts, following the editor's ideas slowly in-depth, let's learn new knowledge together.

Step 1:

Open the development tool to connect to the database and create a new database, as follows:

Var dataBase = openDatabase ("student", "1.0", "student", 1024 * 1024, function () {}); if (! dataBase) {alert ("database creation failed!") ;} else {alert ("Database created successfully!") ;} step 2:

After completing a database, a database table is created to access the data. The code is as follows:

This.createTable = function () {dataBase.transaction (function (tx) {tx.executeSql ("create table if not exists stu (id REAL UNIQUE, name TEXT)", [], function (tx, result) {alert ('stu table created successfully') }, function (tx, error) {alert ('failed to create stu table:' + error.message);} step 3:

After the table is created, we need to perform a step of adding, deleting, modifying and querying the database. The code is as follows:

This.insert = function () {dataBase.transaction (function (tx) {tx.executeSql ("insert into stu (id, name) values (?)", [id, 'Xiao Ming'] Function () {alert ('data added successfully') }, function (tx, error) {alert ('failed to add data:' + error.message);});}) After reading this, the article "how to connect to the database in HTML5" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Data databases steps success code articles content tables appropriateness tools development tools ideas new knowledge more knowledge knowledge points articles details industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS MySQL Xiaomi vpn