久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      html5用什么數(shù)據(jù)庫

      HTML5使用Web SQL數(shù)據(jù)庫,可用于臨時存儲數(shù)據(jù)。Web SQL數(shù)據(jù)庫API實際上不是HTML5規(guī)范的組成部分,而是單獨的規(guī)范;它通過一套API來操縱客戶端的數(shù)據(jù)庫。Chrome、Firefox等主流瀏覽器都支持Web SQL數(shù)據(jù)庫。

      html5用什么數(shù)據(jù)庫

      本教程操作環(huán)境:windows7系統(tǒng)、HTML5版、Dell G3電腦。

      HTML5使用Web SQL數(shù)據(jù)庫。

      html 5 本地數(shù)據(jù)庫(Web Sql Database)

      Web SQL數(shù)據(jù)庫API實際上不是HTML5規(guī)范的組成部分,而是單獨的規(guī)范。它通過一套API來操縱客戶端的數(shù)據(jù)庫。Safari、Chrome、Firefox、Opera等主流瀏覽器都已經(jīng)支持Web SQL Database。HTML5的Web SQL Databases的確很誘惑人,當(dāng)你發(fā)現(xiàn)可以用與mysql查詢一樣的查詢語句來操作本地數(shù)據(jù)庫時,你會發(fā)現(xiàn)這東西挺有趣的。今天,我們一起來了解HTML 5的Web SQL Database API。

      下面將一一將介紹怎樣創(chuàng)建打開數(shù)據(jù)庫,創(chuàng)建表,添加數(shù)據(jù),更新數(shù)據(jù),刪除數(shù)據(jù),刪除表 。

      先介紹三個核心方法

      1、openDatabase:這個方法使用現(xiàn)有數(shù)據(jù)庫或創(chuàng)建新數(shù)據(jù)庫創(chuàng)建數(shù)據(jù)庫對象。

      2、transaction:這個方法允許我們根據(jù)情況控制事務(wù)提交或回滾。

      3、executeSql:這個方法用于執(zhí)行真實的SQL查詢。

      第一步:打開連接并創(chuàng)建數(shù)據(jù)庫

      var dataBase = openDatabase("student", "1.0", "學(xué)生表", 1024 * 1024, function () { });if (!dataBase) { alert("數(shù)據(jù)庫創(chuàng)建失敗!"); } else { alert("數(shù)據(jù)庫創(chuàng)建成功!"); }

      解釋一下openDatabase方法打開一個已經(jīng)存在的數(shù)據(jù)庫,如果數(shù)據(jù)庫不存在,它還可以創(chuàng)建數(shù)據(jù)庫。幾個參數(shù)意義分別是:
      1,數(shù)據(jù)庫名稱。
      2,版本號 目前為1.0,不管他,寫死就OK。
      3,對數(shù)據(jù)庫的描述。
      4,設(shè)置數(shù)據(jù)的大小。
      5,回調(diào)函數(shù)(可省略)。
      初次調(diào)用時創(chuàng)建數(shù)據(jù)庫,以后就是建立連接了。
      創(chuàng)建的數(shù)據(jù)庫就存在本地,路徑如下:
      C:UsersAdministratorAppDataLocalGoogleChromeUser DataDefaultdatabaseshttp_localhost_* 。
      創(chuàng)建的是一個sqllite數(shù)據(jù)庫,可以用SQLiteSpy打開文件,可以看到里面的數(shù)據(jù)。SQLiteSpy是一個綠色軟件,可以百度一下下載地址或SQLiteSpy官方下載:SQLiteSpy。

      第二步:創(chuàng)建數(shù)據(jù)表

      this.createTable=function() { dataBase.transaction( function(tx) {  tx.executeSql("create table if not exists stu (id REAL UNIQUE, name TEXT)",  [],  function(tx,result){ alert('創(chuàng)建stu表成功'); },  function(tx, error){ alert('創(chuàng)建stu表失敗:' + error.message);  }); }); }

      解釋一下,
      executeSql函數(shù)有四個參數(shù),其意義分別是:

      1)表示查詢的字符串,使用的SQL語言是SQLite 3.6.19。(必選)

      2)插入到查詢中問號所在處的字符串?dāng)?shù)據(jù)。(可選)

      3)成功時執(zhí)行的回調(diào)函數(shù)。返回兩個參數(shù):tx和執(zhí)行的結(jié)果。(可選)

      4)一個失敗時執(zhí)行的回調(diào)函數(shù)。返回兩個參數(shù):tx和失敗的錯誤信息。(可選)

      第三步:執(zhí)行增刪改查

      1)添加數(shù)據(jù):

      this.insert = function () { dataBase.transaction(function (tx) { tx.executeSql("insert into stu (id, name) values(?, ?)", [id, '徐明祥'], function () { alert('添加數(shù)據(jù)成功'); }, function (tx, error) { alert('添加數(shù)據(jù)失敗: ' + error.message);  } ); });

      2)查詢數(shù)據(jù)

      this.query = function () { dataBase.transaction(function (tx) { tx.executeSql("select * from stu", [], function (tx, result) { //執(zhí)行成功的回調(diào)函數(shù)//在這里對result 做你想要做的事情吧...........}, function (tx, error) { alert('查詢失敗: ' + error.message); } ); }); }

      特別提醒

      上面代碼中執(zhí)行成功的回調(diào)函數(shù)有一參數(shù)result。

      result:查詢出來的數(shù)據(jù)集。其數(shù)據(jù)類型為 SQLResultSet ,就如同C#中的DataTable。
      SQLResultSet 的定義為:

      interface SQLResultSet {readonly attribute long insertId;readonly attribute long rowsAffected;readonly attribute SQLResultSetRowList rows; };

      其中最重要的屬性—SQLResultSetRowList 類型的 rows 是數(shù)據(jù)集的“行” 。
      rows 有兩個屬性:length、item 。
      故,獲取查詢結(jié)果的第一行列名為name的值 :result.rows.item(0).name 。

      3)更新數(shù)據(jù)

      this.update = function (id, name) { dataBase.transaction(function (tx) { tx.executeSql("update stu set name = ? where id= ?", [name, id], function (tx, result) { }, function (tx, error) { alert('更新失敗: ' + error.message); }); }); }

      4)刪除數(shù)據(jù)

      this.del = function (id) { dataBase.transaction(function (tx) { tx.executeSql("delete from stu where id= ?", [id], function (tx, result) { }, function (tx, error) { alert('刪除失敗: ' + error.message); }); }); }

      5)刪除數(shù)據(jù)表

      this.dropTable = function () { dataBase.transaction(function (tx) { tx.executeSql('drop table stu'); }); }

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號