0

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

1
  • 1
    PHP is a server side language - it will be hosted and served up to the device using a HTTP server -> php.net/manual/en/intro-whatis.php Commented Dec 7, 2011 at 12:45

3 Answers 3

1

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/

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks I get it now! Yeah i have access to the server that I will be getting the information from so Ill be able to upload the php file there. Thanks a million!
Using w3chools is really not the best way forward -> w3fools.com there are so many atternatives .. php.net for one
@davemc No prob! Glad I could be a help. php is an awesome easy-to-learn language with tons of resources out there to help you get started. As the saying goes: Google is your friend...
0

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/.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.