sam
sam

Reputation: 131

How to connect to mysql database using only ajax and javascript?

I am trying to make an app using phone gap that makes users login in. I know how to connect to a mysql database using php but I have no clue on how to connect to it using ajax. I hope someone could show how its done or if there is another way to connect to a mysql database in phonegap.

Thank You

Upvotes: 2

Views: 2306

Answers (2)

Alexander Beletsky
Alexander Beletsky

Reputation: 19821

You can't directly connect to MySQL database from client side.. This is not exactly correct (but I've heard some people doing similar with MongoDB).

Anyway, right approach for this is:

  1. You have to have a server side code (web service) with methods that actually connect to database, perform CRUD operations. This would be you application API.
  2. In client you use that API. If you are on Javascrip, using of jQuery is best.

Upvotes: 4

Federico klez Culloca
Federico klez Culloca

Reputation: 27119

This is not specific to Android.

Anyway, last time I checked, it wasn't possible to connect directly to MySQL via AJAX.

What you need is a back-end (in php, for example) that accepts connection via AJAX and then connects to MySql, processes the data and gives back the results via JSON, XML, plain text or whatever format you prefer.

Upvotes: 2

Related Questions