简体   繁体   中英

Connect android app to an External MySQL database using PHP

I have created a login_activity for my android app. I've gone through quite a few tutorials on how to fetch data from an external MySQL database. I have access to this external MySQL database. I've followed one of them to write the following PHP code which will fetch my data from the server for my login_Activity:

<?php
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);

$dbhost="localhost";
$dbuser="";   
$dbpass=""

$connect=mysql_connect($dbhost,$dbsuer,$dbpass) or die("database selection error");

$username=$_POST['username'];
$password=$_POST['password'];

$query=mysql_query("SELECT * FROM app_users_parent where Email='$username' AND Password='$password');
$num=mysql_num_rows($query);

if($num==1) {

while($list=mysql_fetch_assoc($query)) {
$output=$list;
echo json_encode('$output');
}

mysql_close();

}

?>

I understand I've got to place this php file onto the same server. But I don't really understand how to do that? Should I use something like FileZilla for FTP or what? I could not find any tutorial on the net which shows how and where to save this php file. If you need my Java code where I'm connecting to this file,I could give it to you. (PS- I just started with android so not really a pro out here. Please respect that )

How to connect Android with PHP, MySQL tutorial definitely help you. Good luck.

Yes, you have to upload your .php file onto your server (wich contain the MySQL database).

Then, in you android class, create an asynctask class. That aynsctask class have to request your phpfile an get the json.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM