我想开始使用html5的客户端数据库功能,但我不知道在哪里可以找到一个好的介绍/教程/操作方法。我一直在编码(x)html多年,所以我对“这里是<head>
元素”类型的介绍并不感兴趣;我想了解一般html5中的 new ,特别是客户端db。有什么建议吗?
答案 0 :(得分:3)
亚历克斯, 我在http://wecreategames.com/blog/?p=219编写了详细的方法,包括下载源代码。这里有几个片段:
function picsInitDatabase() {
try {
if (!window.openDatabase) {
console.log('Databases are not supported in this browser');
} else {
var shortName = 'picsGeoDB';
var version = '1.0';
var displayName = 'Pictures Geotagged database';
var maxSize = 5000000; // in bytes
picsDB = openDatabase(shortName, version, displayName, maxSize);
console.log("Database is setup: "+picsDB);
}
} catch(e) {
// Error handling code goes here.
if (e == 2) {
// Version number mismatch.
console.log("Invalid database version.");
} else {
console.log("Unknown error "+e+".");
}
return;
}
}
这是更新表的功能:
function picsUpdateTables(dataID) {
picsDB.transaction(
function (transaction) {
var p = data[dataID];
transaction.executeSql("INSERT INTO geopictures (id, secret, server, farm, title, latitude, longitude, accuracy, datetaken, ownername) VALUES (?,?,?,?,?,?,?,?,?,?);",
[p.id, p.secret, p.server, p.farm, p.title, p.latitude, p.longitude, p.accuracy, p.datetaken, p.ownername] );
transaction.executeSql("INSERT INTO photodata (picid, encodedtext) VALUES (?, ?)", [p.id, serializeCanvasByID(p.id)] );
}
);
}
有关如何执行SQL SELECTS的示例,请参阅博客文章,以及显示如何在少数浏览器上测试它的视频。
答案 1 :(得分:0)