web sql databases 介绍

websql databases 浏览器端的数据库并不是html5标准规范的一部分,但是它也属于html5 范畴内的技术,有必要深入的学习和了解下。

浏览器端的数据库大部分是基于SQLite (3.1.19),还有一少部分是基于mysql.

支持的浏览器 Safari, Chrome and Opera 10.50)

核心方法

1 openDatabase()

var db = openDatabase('mydb', '1.0', 'my first database', 2 *1024 * 1024);

  1. Database name
  2. Version number
  3. Text description
  4. Estimated size of database

2 transaction()

db.transaction(function (tx) {
  // here be the transaction
  // do SQL magic here using the tx object
});

3 executeSql()

db.transaction(function (tx) {
  tx.executeSql('CREATE TABLE foo (id unique, text)');
  tx.executeSql('SELECT * FROM foo', [], function (tx, results){
  var len = results.rows.length, i;
  for (i = 0; i < len; i++) {
    alert(results.rows.item(i).text);
  }
});
});

patchy 拼凑成 specification 规范 recommend 推荐 determine 确定 assume 假设

出处:http://html5doctor.com/introducing-web-sql-databases/

posted @ 2015-07-22 09:43  一渡  阅读(136)  评论(0)    收藏  举报