Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 连接到Android时,我是否必须为每个CRUD方法创建单独的php文件?_Java_Php_Android_Mysql_Connect - Fatal编程技术网

Java 连接到Android时,我是否必须为每个CRUD方法创建单独的php文件?

Java 连接到Android时,我是否必须为每个CRUD方法创建单独的php文件?,java,php,android,mysql,connect,Java,Php,Android,Mysql,Connect,我一直在网上看关于用Android连接PHP的例子,例如。我看到的大多数示例都是这样的,它们只为一个数据库方法(如get、read或delete)创建一个php文件。因此,这是否意味着我必须为要查询的数据库表的每个不同CRUD方法创建一个单独的PHP文件?没有办法遵循通常的“模型”模型,将所有CRUD方法都放在一个PHP文件中吗?试试看 $hostname_localhost ="localhost"; $database_localhost ="mydatabase"; $username_l

我一直在网上看关于用Android连接PHP的例子,例如。我看到的大多数示例都是这样的,它们只为一个数据库方法(如get、read或delete)创建一个php文件。因此,这是否意味着我必须为要查询的数据库表的每个不同CRUD方法创建一个单独的PHP文件?没有办法遵循通常的“模型”模型,将所有CRUD方法都放在一个PHP文件中吗?

试试看

$hostname_localhost ="localhost";
$database_localhost ="mydatabase";
$username_localhost ="root";
$password_localhost ="";

$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);
博览群书


最好使用JSON接口与PHP/MySQL服务器通信。如果愿意,您可以轻松地将所有CRUD方法放在一个文件中


以下是入门指南:

您可以使用POST或get方法在同一个PHP文件上执行不同的操作

例如,在android上

  • 要获取所有表,请转到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();
    ?>