智能方式复制/转储服务器数据库表数据在Android和iOS应用程序中使用PHP编写的Web服务


Smart way to Copy/Dump Server database tables data in Android and iOS Application using Web service written in PHP

我的服务器数据库中有30多个表。所以,需要得到表中所有的数据应该使用一个web服务为Android,iOS应用程序检索。

考虑以下几点:

    我有一些统计信息utf-8数据存储在服务器数据库的不同表中。
  • 所以我需要俱乐部的所有表数据json/其他格式。
  • 我可以在应用程序端使用web服务获取json/其他格式。
例如(如果考虑JSON),我们考虑三个表:
  • 表A (id,name,address)

  • 表B(键,值)

  • 表C (title,price)

在这种情况下,web服务应该返回以下响应:

[
    {
        "A": [
            {
                "id": 1,
                "name": "ABC",
                "address": "XYZ"
            },
            {
                "id": 2,
                "name": "ABC",
                "address": "XYZ"
            }
        ]
    },
    {
        "B": [
            {
                "key": "test",
                "value": "XYZ"
            },
            {
                "key": "test1",
                "value": "LMN"
            }
        ]
    },
    {
        "C": [
            {
                "title": "PQR",
                "price": 20.5
            },
            {
                "title": "XYZ",
                "price": 20
            }
        ]
    }
]

  1. 我如何写Web服务在PHP返回我json显示在上面的例子?

    (注意:我已经尝试过在每个所需的表上点击单独的查询,但需要2-3分钟才能返回数据)。

  2. Web Service应该在5-7秒内返回数据

你是说这样吗?

    //queries
    $sql1 = "SELECT * from A";
    $sql2 = "SELECT * from B";
    $sql3 = "SELECT * from C";
    //prepare
    $stmt1 = $dbh->prepare( $sql1 );
    $stmt2 = $dbh->prepare( $sql2 );
    $stmt3 = $dbh->prepare( $sql3 );
    //execute
    $stmt1->execute();
    $stmt2->execute();
    $stmt3->execute();
    //get results
    $result1 = $stmt1->fetchAll( PDO::FETCH_ASSOC );
    $result2 = $stmt2->fetchAll( PDO::FETCH_ASSOC );
    $result3 = $stmt3->fetchAll( PDO::FETCH_ASSOC );
    //convert to json
    $json1 = json_encode($result1, true);
    $json2 = json_encode($result2, true);
    $json3 = json_encode($result3, true);
    //merge jsons
    $json = json_encode(array_merge($json1, $json2, $json3));
    //echo result
    echo $json;