Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6652515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:08:55+00:00 2026-05-26T01:08:55+00:00

I’m trying to use html5’s web-database using phonegap for an iOS app for the

  • 0

I’m trying to use html5’s web-database using phonegap for an iOS app for the first time. But I’m stuck at this error which says “result of expression mybd.transaction is not a function”

If I check using alerts, initDB is getting executed but when it comes to createTables function, the above error rises and I’m helpless from thereon.

I’ve used this implementation -> http://wiki.phonegap.com/w/page/16494756/Adding%20SQL%20Database%20support%20to%20your%20iPhone%20App

<script type="text/javascript">
    function validateFloat()
    {
        var mydb=false;
        var fuelUnits = document.myForm.UnitsOfFuel;
        var bFuelUnits = false;
        var bUnitPrice = false;
        switch (isNumeric(fuelUnits.value))
        {
            case true:
            bFuelUnits = true;
            fuelUnits.style.background="white";
            break;
            case false:
            fuelUnits.focus();
            fuelUnits.style.background="yellow";
            break;
        }
        var unitPrice = document.myForm.PricePerUnit;
        switch (isNumeric(unitPrice.value))
        {
            case true:
            bUnitPrice = true;
            unitPrice.style.background="white";
            break;
            case false:
            unitPrice.focus();
            unitPrice.style.background="yellow";
            break;
        }
        if(bFuelUnits && bUnitPrice)
        {
            if(initDB(mydb))
            {
                if(createTables(mydb))
                {   
                    loadCelebs();
                    return true;
                }
                else
                    return false;
            }
            else
                return false;
        }
        else
        {
            return false;
        }
    }
    function isNumeric(n)
    {
        var n2 = n;
        n = parseFloat(n);
        return (n!='NaN' && n2==n);
    }

    // initialise the database

    function initDB(mydb) 
    {
        try 
        { 
            if (!window.openDatabase) 
            { 
                alert('not supported'); 
                return false;
            } 
            else 
            { 
                var shortName = 'phonegap'; 
                var version = '1.0'; 
                var displayName = 'PhoneGap Test Database'; 
                var maxSize = 65536; // in bytes 
                mydb = openDatabase(shortName, version, displayName, maxSize);
                alert("initDB");
                return true;
            }
        } 
        catch(e) 
        { 
            // Error handling code goes here. 
            if (e == INVALID_STATE_ERR) 
            { 
                // Version number mismatch. 
                alert("Invalid database version."); 
                return false;
            } 
            else 
            { 
                alert("Unknown error "+e+"."); 
                return false;
            } 
            return true; 
        } 
    }

    // db error handler - prevents the rest of the transaction going ahead on failure
    function errorHandler(transaction, error) 
    { 
        alert("errorHandler");
        // returns true to rollback the transaction
        return true;  
    }

    // null db data handler
    function nullDataHandler(transaction, results) 
    { 

    } 

    // create tables for the database
    function createTables(mydb) 
    {

        try 
        {
            mydb.transaction(

                             function(tx) {

                             tx.executeSql('CREATE TABLE celebs(id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL DEFAULT "");', [], nullDataHandler(tx,results), errorHandler(tx,error)); 

                             tx.executeSql('insert into celebs (id,name) VALUES (1,"Kylie Minogue");', [], nullDataHandler(tx,results), errorHandler(tx,error)); 

                             tx.executeSql('insert into celebs (id,name) VALUES (2,"Keira Knightley");', [], nullDataHandler(tx,results), errorHandler(tx,error)); 

                             });
            alert("createTables");
            return true;
        } 
        catch(e) 
        {
            alert(e.message);
            return false;
        }
    }

    // load the currently selected icons
    function loadCelebs()
    {
        try 
        {
            mydb.transaction(
                function(tx) {
                tx.executeSql('SELECT * FROM celebs ORDER BY name',[], celebsDataHandler(tx,results), errorHandler(tx,error));
                });
        } 
        catch(e) 
        {
            alert(e.message);
        }
    } 


    // callback function to retrieve the data from the prefs table
    function celebsDataHandler(transaction, results) 
    {
        alert("here also?");
        // Handle the results 
        var html = "<ul>"; 
        for (var i=0; i<results.rows.length; i++) 
        { 
            var row = results.rows.item(i); 
            html += "<li>"+row['name']+"</li>\n";
        } 
        html +="</ul>";
        alert(html);
    }

</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:08:55+00:00Added an answer on May 26, 2026 at 1:08 am

    You need to return the newly created mydb instance that is created within the initDB() function and then use the returned instance.

    If you are reassigning a new value to a parameter that is passed into a function (which is what you are doing), it needs to be returned or the changes will be lost.

    Note that if you are passing in an object to the function (which you are not doing), you can modify properties of that object and those changes will be persisted outside the scope of that function.

    function initDB(mydb) {
        mydb.initialized = true;
    }
    mydb.initialized = false;
    initDB(mydb);
    // mydb.initialized => true
    

    vs…

    function initDB(mydb) {
        mydb = new DB(); // new reference
        mydb.initialized = true;
    }
    mydb.initialized = false;
    initDB(mydb);
    // mydb.initialized => false
    

    Of course, you are also passing in a primitive boolean value, not an object. Primitives are passed by value so you must return the newly created mydb.


    UPDATE

    You are also using your passed-in transaction handlers wrong. Look at the phone gap wiki again to see how they are assigning the function references to variables and passing those references into the transaction methods. As it is now, you are calling the functions instead of passing them.

    So, instead of this (what you are doing now):

    function errorHandler(tx, error) {
        alert("error");
        return true;  
    }
    function nullDataHandler(tx, results) { }
    
    tx.executeSql('insert into celebs (id,name) VALUES (1,"Kylie Minogue");', [], nullDataHandler(tx, results), errorHandler(tx, error));
    

    do this:

    var errorHandler = function (tx, error) {
        alert("error");
        return true;  
    }
    var nullDataHandler = function(tx, results) { }
    
    tx.executeSql('insert into celebs (id,name) VALUES (1,"Kylie Minogue");', [], nullDataHandler, errorHandler);
    

    I hope this clears it up. Also, remember, if this answered your question, upvote it and mark it as the answer for a reference to future visitors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am using Paperclip to handle profile photo uploads in my app. They upload
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.