Current location: Hot Scripts Forums » General Web Coding » HTML5 » Getting started with HTML5's new local databases --- THE SYNTAX part


Getting started with HTML5's new local databases --- THE SYNTAX part

Reply
  #1 (permalink)  
Old 10-27-10, 02:10 AM
edson1314 edson1314 is offline
Newbie Coder
 
Join Date: Oct 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Getting started with HTML5's new local databases --- THE SYNTAX part

This is cool,do you think so?
So you've probably heard a lot about the new HTML, HTML5. This is tutorial is about one of my favorite new specifications from it, client-side databases. This new specification will be popular, web-apps are now changing the web and portability it the key. People don't have the internet everywhere (yet) so this is where client-side functionality comes in, these databases allow for storage offline and when connection is available, update online.

Creating the database

PHP Code:

openDatabase(shortNameversiondisplayNamemaxSize); 

We use the openDatabase to create and open a database. This function which has a few specific parameters.

* shortName - This is basically the name you will use to reference the database. Keep it simple and distinguishable.
* version - This is a string, so anything is generally accepted i.e using the alpha (α) or beta (β) symbols
* displayName - Just for readability, has no real effect on the database.
* maxSize - An integer which states the maximum size of the database in bytes

Querying the database

PHP Code:

database.transaction(

 function (
transaction) {
        
//Usage: transaction.executeSql(_QUERY_, [vars], callback);
        //Create Table
        
transaction.executeSql("CREATE TABLE foobar(id, foo, bar)");
        
//Insert data into database
        
transaction.executeSql("INSERT INTO table_name(foo, bar) VALUES(?, ?)", ['foo''bar']);
} ); 
The transaction function is basically the wrapper for the executeSql function. ExecuteSql is the vital function for querying the database. The parameters for executeSql is just the SQL query.

Getting the data

PHP Code:

//Your query

function(transaction) {
        
transaction.executeSql("SELECT * FROM sample", [], retrieveData); //The retrieveData function is where the data is sent/returned to in parameters (transation, results)
}); 
The key to retrieving the data is to send it to a function to parse and use/display it. As in the example above, I use a function called retriveData. The data is sent as a parameter in the function.

PHP Code:

function retrieveData(transactionresults) {

        
//Usage: results.rows.item(int)[columnName];
        
        //Loop through the data, similar to using PHP etc.
        
for(var 0results.rows.lengthi++) {
            
//This will return the data from row i (the integers from loop) from the column 'foobar' 
            
var data results.rows.item(i)['foobar']
        }

To access the data, we need to use the results parameter. The data is a bit different from accessing normal Javascript variables as it needs the keywords rows and item(). Item(int) needs an integer to select a specific row, it does not return every row. This will return a Javascript object with the data in that row. After we have our row selected, we select a column we want the data returned from, so we add our column name after item() e.g item(2)['foo'] This is exactly the same as if you were retrieve data in a normal JS Object.
Reply With Quote
  #2 (permalink)  
Old 08-31-11, 12:52 PM
porimoll porimoll is offline
New Member
 
Join Date: Aug 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Keep on reading if you want to use this approach to backlinking. Whether you’re creating links to your 300 internet marketers internet site or any other website, you must focus on using whitehat strategies to obtain long term results.
Use Forum Posting: When dealing with whitehat link building, you should always remember to use forums and discussion boards. Numerous available forums are okay with you placing your website link in the signature of your forum post. If your website is about one particular subject, the chances are high that you can find and post on a forum that focuses on the same subject. However, in order to make forum link building really work for you, you should only select forums that are active. This is because active forums are considered to be valuable by the search engines. So, you must focus on the amount as well as the value. In addition, when you first start out putting your links in your signature posts, you will get new people to your website because they clicked on this link to your blog.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Error Nikas Database 4 05-15-08 10:48 AM


All times are GMT -5. The time now is 09:30 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.