【问题标题】:Do I have to create a separate php file for each CRUD method when connecting to Android?连接到 Android 时是否必须为每个 CRUD 方法创建一个单独的 php 文件?
【发布时间】:2013-06-13 04:34:50
【问题描述】:
【问题讨论】:
标签:
java
php
android
mysql
connect
【解决方案3】:
您可以使用 POST 或 GET 方法对同一个 PHP 文件执行不同的操作..
例如,在安卓上,
- 要获取所有表格,请访问 yoururl.com/?iwantto=select
- 要插入,您可以访问 yoururl.com/?iwantto=insert&data=asdf
在 php 中:
<?php
mysql_connect("host","username","password");
mysql_select_db("Deal");
$iwantto = $_GET['iwantto'];
if($iwantto=="select"){
$sql=mysql_query("select * from CITY");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
}
else if($iwantto=="insert")
{
$data=$_GET['data'];
mysql_query("delete from CITY where CITY_NAME like '".$data."'");
}
mysql_close();
?>