2
웹 서버에서 mysql 데이터베이스를 읽어야하는 안드로이드 응용 프로그램이 있습니다.
이 웹 serivce에서 코드입니다 :httpclient를 사용하여 웹 서비스에서 읽기
$q=mysql_query("SELECT * FROM Rates");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
이 내 응용 프로그램의 코드입니다 : 결과 문자열 쿼리를하지 않는 몇 가지 이유를 들어
public void getQuery() {
String result = "";
InputStream is;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://dakatora.co.il/android/androidsql.php");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
is = new InputStream() {
@Override
public int read() throws IOException {
// TODO Auto-generated method stub
return 0;
}
};
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//parse json data
, 대신하다 그냥 "\ n"이됩니다. 누군가 잘못된 정보를 알려주실 수 있습니까?
당신은, 나는 다음과 같은 오류를 바로 얻을 수 있었다 : 치명적인 오류 : 라인 11 에 /var/www/vhosts/dakatora.co.il/httpdocs/android/androidsql.php에서 정의되지 않은 함수로 json_encode()로 부르는 내가해야만 해? – eladrich
당신은 아마 구 버전의 PHP를 사용하고있을 것입니다. json_encode()는 v5.2부터 표준이되었으므로 이전 PECL 패키지 (http://pecl.php.net/package/json)를 사용해 보거나 최신 PHP 버전으로 업그레이드해야합니다. –
고마워, 나는 내가 할 수있는 것을 보게 될 것이다 (나는 자바 어플리케이션을 작성한다. 동료가 웹 서비스를 유지 관리한다). – eladrich