6

I am doing a phone gap-android project for a library system. I don't have much idea about mobile application development. I am using MySQL to create the database and need to populate HTML pages in my application. How can I do it? I have no idea even how to start connecting to an external database. And I want to display existing values in db as well as want to add new values from application.

Cœur
  • 37,241
  • 25
  • 195
  • 267
vishee
  • 71
  • 1
  • 1
  • 4
  • Have a look at [Phonegap documentaion.](http://docs.phonegap.com/en/2.9.0/index.html) – Amol Chakane Jul 18 '13 at 12:35
  • I have checked it.But it is not much clear to me.I want some sample coding on how to connect to external database(I use MySQL workbench) – vishee Jul 22 '13 at 03:55
  • Use web services to GET/POST data from/to server. To call web services in phonegap use `$.ajax` – Amol Chakane Jul 22 '13 at 06:42
  • here Amol .Im doing this as part of my 3rd year project.But actually I'm a Network Engineering student and have less idea about programming .It would be a great help if you can give me little bit more guidance. thnx in advance – vishee Jul 23 '13 at 05:16

1 Answers1

9

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

  1. Creating PHP web services Tutorial
  2. 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.

Nurdin
  • 23,382
  • 43
  • 130
  • 308
Amol Chakane
  • 1,501
  • 2
  • 21
  • 43
  • thnx a lot ,I have created a web form to connect to my database.I want to connect the database externally.Is there a way to convert web form to web service? – vishee Jul 23 '13 at 07:21
  • Are you using PHP as a server side language? – Amol Chakane Jul 23 '13 at 08:23
  • yeah and i got to know wampserver is better to code php.There is a web form i have created .Can i use it as a web service using php to connect to external database? – vishee Jul 23 '13 at 14:47
  • I am not much familiar with PHP but, I suspect you cannot use the web form as it is because web service must return data in `xml/json` format. But you can always reuse the code of web form in web service. Refer the links I have provided in above answer. – Amol Chakane Jul 24 '13 at 09:59
  • hey I asked from a lecturer and thought of using c# in visual studio.U think that's a good idea.I think i can use windows services there.I use Visual studio 2010 :) .What you think??? – vishee Jul 24 '13 at 13:57
  • I suspect you cannot consume windows services in phonegap app. You can create `web services using ASP.NET` – Amol Chakane Jul 25 '13 at 05:43
  • ohh ok so are you saying we can use web services instead windows servises to connect to both database and phonegap app?? web services also available in visual studio :) – vishee Jul 25 '13 at 06:04
  • Yes. Your app will connect to a database using web service. – Amol Chakane Jul 25 '13 at 07:30
  • thnx :) hope I'l be able to get little help if get stuck :) – vishee Jul 27 '13 at 12:54
  • Sure :) anytime. And Good Luck!! with your project. :) – Amol Chakane Jul 29 '13 at 04:47
  • thnx :) hey Amol,in Visual studio,there is a thing called WCF services,not web services,Is it the same?? Can you send me a link or tell me a way to create this web service in VS2010?? or do i have to use any other software?I just need a boost for the start.No need the whole coding stuff...thank you :) – vishee Jul 30 '13 at 05:39
  • Yes in `.NET` there are` WCF services` and `ASMX web services`. **Refer these links:** [1. Differences Between ASMX and WCF Services](http://msdn.microsoft.com/en-us/library/ff648181.aspx) [2. Another link for Difference](http://www.topwcftutorials.net/2012/06/wcf-vs-asmx-web-services.html) [3. Creating ASMX web services](http://www.codeproject.com/Articles/45275/Create-a-JSON-WebService-in-ASP-NET-2-0-with-a-jQu) [4. Creating WCF web services](http://www.codeproject.com/Articles/327420/WCF-REST-Service-with-JSON). Hope that helps – Amol Chakane Jul 30 '13 at 06:17
  • thnq :) btw can $ajax messages work with WCF?? In those tutorials they say it is compatible with any.just to make sure :) – vishee Jul 30 '13 at 14:44