Comments: This article will introduce in detail how to use SQL statements of HTML5 Web Database. For more information, see // openDatabase to open an existing Database, if it does not exist, a database will be created. The parameters are the database name, version, database description, and data size. var db = window. openDatabase ("mydatabase", "1.0", "My database description", 20000 );
How to Use Database SQL statements
Dbname. transaction (function (tx) {tx.exe cuteSql (SQL );});
The Code is as follows:
<! DOCTYPE html>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> </title>
<Style type = "text/css">
</Style>
</Head>
<Body>
<Div>
</Div>
<Script type = "text/javascript">
// Open an existing database using the openDatabase method. If it does not exist, a database will be created.
Var db = window. openDatabase ("mydatabase", "1.0", "My database description", 20000 );
Var d = new Date ();
// Create a data table
Var SQL = "CREATE TABLE mytable (mytitle TEXT, timestamp REAL )";
Db. transaction (function (tx ){
Tx.exe cuteSql (SQL );
});
// Insert data into the data table
Db. transaction (function (tx ){
Tx.exe cuteSql ("insert into mytable (mytitle, timestamp) values (?, ?) ", [" Guangzhou University huasoft software College 3 ", d. toLocaleString ()], null, null );
});
// Delete a data table
// Db. transaction (function (tx ){
// Tx.exe cuteSql ("drop table mytable ");
//});
Db. transaction (function (tx ){
Tx.exe cuteSql ("SELECT * FROM mytable", [],
Function (tx, result ){
For (var I = 0; I <result. rows. length; I ++ ){
Document. write ('Result. rows. item (I) ['mytitle'] + "" +
Result. rows. item (I) ['timestamp'] +
'</H1> ');
}
},
Function (){
Alert ("error ");
});
});
</Script>
</Body>
</Html>