websql

来源:互联网 发布:怎样降低淘宝纠纷率 编辑:程序博客网 时间:2024/05/29 08:26
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>sql</title>
    </head>
    <body>
        <script>
            var db=openDatabase("web001","1","humanmessage",1024*4);
            function createSql () {
                db.transaction(function  (txobject) {
                    txobject.executeSql("create table if not exists avlon(name text,message text,time integer)",[],function  () {
                        console.log("succes");
                    },function  () {
                        console.log("faile");
                    })
                })
            }
            createSql();

            function insertSql (name,message,time) {
                db.transaction(function(txobject){
                    txobject.executeSql("insert into avlon values(?,?,?)",[name,message,time],function  () {
                        console.log("数据插入成功");
                    },function(){
                        console.log("数据插入失败");
                    })
                })
            }

            function select (){
                db.transaction(function(tx){
                    tx.executeSql("select * from avlon",[],function(tx,rs){
                        for (var i=0;i<rs.rows.length;i++) {
                            console.log(rs.rows.item(i).name)
                        }
                    },function(){

                    })
                })
            }
            insertSql("wanzhuhao","feichangdiao",new Date().getTime());
            insertSql("fnahuizhong","mywifi",new Date().getTime());
            select();
        </script>
    </body>
</html>

0 0
原创粉丝点击