duanhongqiong9460 2018-05-01 04:42
浏览 118

没有从android中的改进获得完整的字符串响应

I am trying to execute the following query in my PHP file.

show create table test.account;

When I echo the response I am only getting the first word of the query i.e. CREATE. I surrounded the whole query by single quotes but when I echo the response I only get the response from first single quote to next single quote (next single quote is used for some default string), not the whole query.

Following is my API interface code -

@GET("createQueries.php/")
Call<String> loadCreateQueries(@Query("tableName") String tableName);

My PHP code -

 <?php

    include_once 'db_functions.php';
    $db = new DB_Functions();

    require_once 'config.php';
    // connecting to mysql
    $con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if ( !$con){
        echo "Database Connection Error";
    }

    // selecting database
    $select = mysqli_select_db($con,DB_DATABASE);
    if ( !$select){
        echo "Database Selection Error";
    }

    $tableName = $_GET["tableName"];


    $result = mysqli_query($con, "SHOW CREATE TABLE test.".$tableName);

    if ($result != false) {
        $create_query = "'{";
        while ($row = mysqli_fetch_assoc($result)) {
            $fields = array_values($row);
            $create_query = $create_query.$fields[1];
        }
        $create_query = $create_query."}'";
        echo $create_query;
    } else {
        echo "Table not in server";
    }

?>

Response

{CREATE TABLE `account` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `amount` float DEFAULT NULL,
  `interestRate` float DEFAULT NULL,
  `totalInterestReceived` float DEFAULT 

Client code -

  public void createTable() {
    if (tableNames.length > tableIndex) {
        NetworkUtil.getAPI(getApplicationContext()).loadCreateQueries(tableNames[tableIndex]).enqueue(new Callback<JsonElement>() {
            @Override
            public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {
                progressDialog.dismiss();
                if (response.isSuccessful()) {
                    String query = response.body().getAsString();
                    Log.d("Create Query - ", query);

                } else System.out.println(response.errorBody());
            }

            @Override
            public void onFailure(Call<JsonElement> call, Throwable t) {
                t.printStackTrace();
            }
        });
    }
}
  • 写回答

1条回答 默认 最新

  • douren1891 2018-05-01 05:01
    关注

    I don't know if it's the best approach but I replace the single quotes by %27 and before echo, I had surrounded it by single quotes.

    Here is updated code -

    if ($result != false) {
        $create_query = "";
        while ($row = mysqli_fetch_assoc($result)) {
            $fields = array_values($row);
            $create_query = $create_query.$fields[1];
        }
        //$create_query = $create_query."";
    
        $create_query = str_replace('\'', '%27', $create_query);
        echo "'".$create_query."'";
    } else {
        echo "Table not in server";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch