Home Web Front-end H5 Tutorial Detailed explanation of phonegap operation database

Detailed explanation of phonegap operation database

Mar 26, 2018 pm 03:02 PM
database Detailed explanation

This time I will bring you a detailed explanation of the phonegap operation database, what are the precautions for phonegap operation database, the following is a practical case, let's take a look.

The examples are as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

<!DOCTYPE html> 

<html> 

   

    <head> 

        <meta charset="UTF-8"> 

        <title>Database Example</title> 

   

        <script type="text/javascript" charset="UTF-8" src="cordova.js"></script> 

        <script type="text/javascript" charset="UTF-8"> 

            document.addEventListener("deviceready", onDeviceReady, false); 

   

            function onDeviceReady() { 

                var db=window.openDatabase("Test","1.0","Test",200000); 

                db.transaction(populateDB,errorDB,successDB); 

            

               

            //初始化数据库数据 

            function populateDB(tx){ 

                tx.executeSql('DROP TABLE IF EXISTS test1'); 

                tx.executeSql('CREATE TABLE IF NOT EXISTS test1 (id unique,name)'); 

                tx.executeSql('INSERT INTO test1(id,name) VALUES(1,"Tony")'); 

                tx.executeSql('INSERT INTO test1(id,name) VALUES(2,"Bill")'); 

                tx.executeSql('INSERT INTO test1(id,name) VALUES(3,"Tony")'); 

            

               

            //查询方法 

            function queryDB(tx){ 

                tx.executeSql('SELECT * FROM test1',[],querySuccess,errorDB); 

            

               

            //查询成功回调 

            function querySuccess(tx,results){ 

                var len=results.rows.length; 

                var status=document.getElementById("status"); 

                var string ="Rows:"+len+"<br />"

                for(var i=0;i<len;i++){ 

                    string+=results.rows.item(i).name+"<br />"

                

                status.innerHTML=string; 

            

               

            //执行初始化数据成功后的回调 

            function successDB(){ 

                var db=window.openDatabase("Test","1.0","Test",200000); 

                db.transaction(queryDB,errorDB); 

            

               

            //失败回调 

            function errorDB(err){ 

                alert('Error processing SQL:'+err.code); 

            

               

        </script> 

    </head> 

   

    <body> 

        <h1>Names</h1> 

        <p id='status'></p> 

    </body> 

   

</html>

Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website !

Recommended reading:

Detailed explanation of creating contacts with phonegap

How to change the code of the current url without refreshing

The above is the detailed content of Detailed explanation of phonegap operation database. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

How does Go language implement the addition, deletion, modification and query operations of the database?

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

How does Hibernate implement polymorphic mapping?

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

Analysis of the basic principles of MySQL database management system Analysis of the basic principles of MySQL database management system Mar 25, 2024 pm 12:42 PM

Analysis of the basic principles of MySQL database management system

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

An in-depth analysis of how HTML reads the database

Tips and practices for handling Chinese garbled characters in databases with PHP Tips and practices for handling Chinese garbled characters in databases with PHP Mar 27, 2024 pm 05:21 PM

Tips and practices for handling Chinese garbled characters in databases with PHP

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How does Go WebSocket integrate with databases?

See all articles