DMC
DMC

Reputation: 1194

Connecting to MySQL Database using PHP from an Android Device

I am trying to connect to MySQL using PHP from an Android Device. I am following this tutorial: http://blog.sptechnolab.com/2011/02/10/android/android-connecting-to-mysql-using-php/

My question is where does the php file go that you create? Is that included in your Android Project or where do i run it from?

Thanks

Upvotes: 0

Views: 3200

Answers (3)

eric
eric

Reputation: 4951

To answer your questions:

1) The php file is not included on the Android device.
2) You need to create the .php file and upload it to a server.

Now, I'm not sure how much you know about php, but just in case you are a beginner, you can easily create .php files using a text editor application such as Text Edit (Mac) or Notepad (Windows). Do you control a server or have a website somewhere? If so, you can upload the file to a location there.

How the php file will work: First, your android device (once your finish that tutorial you cited) will send a request to the php file on your server, and the php file will then connect to the MySQL database, and generate some output which your Android app can get back (ex. to know the result of the MySQL connection attempt, etc)

*Going Further If you want a super-easy tutorial on php check out W3 Schools excellent php section: http://www.w3schools.com/php/

Upvotes: 1

Manse
Manse

Reputation: 38147

Using the example of the link you posted .. the server is http://10.0.2.2/

HttpPost httppost = new HttpPost("http://10.0.2.2/city.php");

PHP is a server side language and is served to the client using a HTTP Server. The MySQL Serve could be on the same host or a different one.

Have a read about PHP here -> http://www.php.net/manual/en/intro-whatis.php

Upvotes: 0

Tobbe
Tobbe

Reputation: 1831

The PHP file resides on the server, as does the MySQL database. This is shown in the first image in the tutorial. This server could be your computer, or it could be on a web host. In the tutorial, the android app creates a JSON call to the web server, which uses PHP to query the database, and return the data to the app. In the example you linked to, the server address is http://10.0.2.2/.

Upvotes: 0

Related Questions