1

サーバー上でphpスクリプトを呼び出すhttpGETリクエストを含むAndroidクライアントがあります。データベースにクエリを実行して結果の行をエコーするサーバー上のphpスクリプトがあります。ここで、blobファイルと他のフィールドをから分離するにはどうすればよいですか。応答?? phpコードがめちゃくちゃになっているような気がします。正しい方向に向けていただければ助かります。ありがとうございます。

My android code:




HttpClient httpClient = new DefaultHttpClient();

        StringBuilder uriBuilder = new StringBuilder("http://192.168.x.x/file_download.php");


        HttpGet request = new HttpGet(uriBuilder.toString());
        HttpResponse response = httpClient.execute(request);

        int status = response.getStatusLine().getStatusCode();
        Log.i("Http Get",response.getStatusLine().toString());

        // we assume that the response body contains the error message
        if (status != HttpStatus.SC_OK) {
     ByteArrayOutputStream ostream = new ByteArrayOutputStream();
     response.getEntity().writeTo(ostream);
         Log.e("HTTP CLIENT", ostream.toString());
        } else {
    //   InputStream content = response.getEntity().getContent();
         // <consume response>

         String type = response.getEntity().toString();
      content.close(); // this will also close the connection

    }

私のphpコード:

<?php

$conn = mysql_connect("localhost", "root", "root");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}

if (!mysql_select_db("MYDB")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}

$sql = "SELECT title, filetype, mode, data, time, application, entity_id 
        FROM   table
        WHERE  id=(select max(id) from file)";

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

$rows = array();

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {



    $rows[]=$row;



}

echo $rows;

mysql_free_result($result);

?>
4

1 に答える 1

0

PHP mysql_ *関数に精通していないため、各行がどのように表示されるかわかりません。

PHPを使用して、サーバー側のデータを、JSONやXMLなどのクライアント側で解析しやすいものにフォーマットするのが最も簡単だと思います。

その部分のPHPもわかりませんが、これは正しい方向への一歩かもしれません。PHPでMySQLレコードセットをJSON文字列に変換する

次に、org.jsonパッケージクラスを使用してクライアント側で解析できます。これは、blobの分離に関する質問に直接対処するものではありませんが、この方法で行うと、JSONオブジェクト(おそらく列の名前でキー設定された)でblobにアクセスできるようになります。

幸運を。

于 2012-01-10T07:09:02.737 に答える