简体   繁体   中英

WebSQL CRUD Function using basic HTML and JavaScript

I have an example database here, which needs CRUD functions to add more data from the UI, its a WebSQL and I cant seem to find a way through, anyone wna help? Users should be able to save and create, read, update and delete their input data.

e

<!DOCTYPE html>
<html>
<head>
    <title>Contact Example</title>

    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8">
            var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
            db.transaction(populateDB, errorCB, successCB);

        // Populate the database
        //
        function populateDB(tx) {
            tx.executeSql('DROP TABLE IF EXISTS DEMO');
            tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
        }

        // Transaction error callback
        //
        function errorCB(err) {
            alert("Error processing SQL: "+err);
        }

        // Transaction success callback
        //
        function successCB() {
            alert("Database created, and polated");
        }

    </script>
</head>
<body>
<h1>Example</h1>
<p>SQLTransaction</p>
</body>
</html>

Websql is CRUD by nature. You will need to learn SQL if you do not know it. There is a tool websql.js that wraps calls in promises for a nicer syntax but very much still uses SQL.

It is not secure to place a db-logic directly into client's html as anyone will be able to see it by looking into a source code. Consider using any server-side scripting (PHP, ASP.NET).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM