0

I'm currently developing an android application. The backend is written in PHP and takes input from the android app and connects it with a MySQL database (similar to http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/).

One of my class files (similar to the UserFunctions.java in the above link) requires the url to be given e.g. private static String loginURL = "http://10.0.2.2/android_api/index.php" so that the requisite communcation can take place. My issue is that all my PHP files are in a folder under \www e.g. \www\blah\. I'm fairly sure that I have put my PHP files in the wrong place as the link (Point 2 of http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/) shows some files being placed in \include\ and the index.php file outside this \include\ directory.

Where should I be placing my PHP files so that my file structure enables my app to communicate with the MySQL database (defined for example as android_api as in the link).

1
  • I would give androidhive.info a wide berth if I were you - plenty of SQL injection vulnerabilities, and the use of a deprecated and unmaintained database library. It is possible to make it safe if needs be - look into mysql_real_escape_string in the manual. Commented Dec 31, 2014 at 11:48

2 Answers 2

0

If you are using wamp it may be in C:/wamp/www/android_api. www is the web root directory. If you call http://10.0.2.2/android_api/index.php, webserver will look the file index.php in the path C:/wamp/www/android_api

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

2 Comments

Thanks Kiren. In your experience, is it natural to get an access denied error when trying to run the a PHP script from a web browser e.g.http://127.0.0.1/blah/index.php?
if the folder and file exists and shows access denied, you have to check if any rule defined in the apache configuration file .htaccess for denying the access
0

I'm fairly certain all of your application's php files should be in www.

I'm not currently developing in Java so you may need to fiddle with what I tell you but the way I access mysql from an external application is this:

Connect to database and perform query within the php file. Then echo the results (JSON encode if necessary)

Then in the external application, simply use the path to the php file:

eg. "http://localhost/your_script.php"

This will be your php file if it is in the root of www

Notice that you do not specify www in the path.

3 Comments

Hi Kyohei, thanks for your input. I've actually got the PHP script performing the connection and query work then transforming to JSON which is then passed to the MySQL server. Only issue I have is knowing where to put these PHP files.
Basically you put all your php files and sub folders within the www directory in wamp. Then from your application you use this is the path: host = "server_ip_or_dns/my_php_file.php"
You may need to edit the config file in Apache to allow access from your application.

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.