How can I connect to an external database with a PhoneGap android app?

cordova, phonegap-plugins

Solution

Your app will reside on a device(android/iOS). So it will be a client side, more like a browser.

And you have communicate to server for getting or posting data.

You must be aware of that, phonegap use jQuery and javascript.

So as I told earlier, if you want to communicate with remote server you will have to call web services in your app using javascript.

Your approach should be:

Server Side:

Create the web services using your server side language.

Assuming you are using PHP as a server side language. Refer following links

- Creating PHP web services Tutorial

- Creating PHP web services PPT

Client Side:

Then you can use `$ajax` to fetch data from server or post data to server.

As far as `$ajax` call concerns, check out the following sample code.

function FetchData() {
$.ajax({
    async: false,
    type: "GET",
    url: "Your_WebService_URL",
    dataType: "json",
    success: function(data, textStatus, jqXHR) {
        $.each(data, function(i, object) {
            alert(obj.Data);
            //Here you can implement your client side logic.
        });
    },
    error: function() {
        alert("There was an error loading the feed");
    }
});

}

I assume it will be at least a kick start.

Hope that helps.

Problem

I am making an android project using PhoneGap for a library system, but I don't know very much about mobile application development. I am using MySQL to create the database and I need to populate HTML pages in my application. How can I do it? I'm not really very sure how to connect to an external database. I want to display existing values in the database as well as add new values from the application.

Original source