티스토리 뷰

PHP서버


<?php

$conn = mysqli_connect("localhost","DB_ID","DB_PW","TABLE_NAME"); // Check connection

if (mysqli_connect_errno()){

 echo "MySQL 연결 실패 : " . mysqli_connect_error();

}

$result = mysqli_query($conn,"SELECT * FROM TABLE");




while($row = mysqli_fetch_array($result)){

 echo "<no='" . $row['_no'] . "' mdn='". $row['mdn'] . "' id='". $row['id'] . "'>\n";

}

mysqli_close($conn);

?>


나의 경우에는 테이블에서 _no , mdn , id 이 3개를 가져온다.

저부분을 수정해서 사용하면 될듯하다.




클라이언트

try 

        {

    URL text = new URL("페이지주소.php");

    HttpURLConnection conn = (HttpURLConnection)text.openConnection();

    conn.connect();

    readStream(conn.getInputStream());

   

        }

        catch (Exception e) { }


private void readStream(InputStream in) {

BufferedReader reader = null;

try {

reader = new BufferedReader(new InputStreamReader(in));

String line = "";

int n = 1;

while ((line = reader.readLine()) != null) {

System.out.println(line);

// no mdn id 

Global.NotifyData.add(new Notify(n+""

line.substring(line.indexOf("mdn='")+5, line.indexOf("' id")), 

line.substring(line.indexOf("id='")+4, line.indexOf("'>"))

));

n++;

}

} catch (IOException e) {

e.printStackTrace();

} finally {

if (reader != null) {

try {

reader.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}



이런식으로 처리하였다. line에 결과값이 나오는데 저부분을 개발자에 맞춰서 잘 짤라쓰거나 하면 될듯하다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함