服务器端:server.php
1 <?php
2 include('dbconfig.php');
3
4
5 $address = $_POST['address'];
6 $longitude = $_POST['longitude'];
7 $latitude = $_POST['latitude'];
8
9
10 if(empty($address) or empty($longitude) or empty($latitude)){
11 die("You have to fill all the fields!");
12 }
13 $conn = mysql_connect($server,$username,$password);
14 if(!$conn){
15 die("connection failed:".mysql_error());
16 }
17
18 mysql_select_db($dbName,$conn);
19
20 $query = "insert into ".$tableName." values(NULL,'".$address."',".$longitude.",".$latitude.",'".date('Y-m-d H:i:s',time())."');";
21 $result = mysql_query($query,$conn);
22 if(!$result){
23 die("mysql error:".mysql_error());
24 }
25
26 echo "add information to database sucessfullly!";
27 ?>

本文详细介绍了如何在Android应用中通过PHP与远程服务器进行数据交互。首先,服务器端使用PHP编写了server.php脚本来处理请求,接着,Android客户端发送HTTP请求到PHP服务器,实现数据的查询和获取。内容涵盖PHP连接MySQL数据库并执行SQL查询,以及Android端的网络请求和数据解析。
最低0.47元/天 解锁文章
1万+





