日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

android php mysql json 查询_android php mysql json

發(fā)布時(shí)間:2023/12/10 数据库 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android php mysql json 查询_android php mysql json 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

$con = mysql_connect("localhost", "db163810_f", "1e6969e2");

if (!$con)

{

die('不能建立連接: ' . mysql_error());

}

$db_selected = mysql_select_db("db163810",$con);

mysql_query("SET NAMES 'utf8'");

if (!$db_selected)

{

die ("這個(gè)數(shù)據(jù)庫(kù)不能被選: " . mysql_error());

}

$sql = "SELECT `ID` , `post_date` , `post_title` , `post_content` FROM `wp_posts` order by `post_date` desc LIMIT 0, 3 ";

$result = mysql_query($sql,$con);

//print_r($result); //Resource id #2

//print($result); //Resource id #2

//echo $result; //Resource id #2

//echo "===================result==============================
";

while($row = mysql_fetch_assoc($result))

{

//print_r(json_encode($row));

//print(json_encode($row));

echo json_encode($row);

echo "
=====================row================================
";

}

mysql_close($con);

?>

mysql數(shù)據(jù)庫(kù)權(quán)限,只允許localhost連接,不能通過(guò)Internet連接

字符集轉(zhuǎn)換

查詢結(jié)果集不能直接輸出,print($result),緊緊輸出資源代碼Resource id #2

輸出了3個(gè)JSON字符串,3對(duì)大括弧

3,android客戶端如何解碼?

DefaultHttpClient httpClient = new DefaultHttpClient();

HttpPost httpPost = new HttpPost("htttp:localhost/mysql.php");

httpPost.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));

//params:List php接收

HttpResponse httpResponse = httpClient.execute(httpPost);

HttpEntity httpEntity = httpResponse.getEntity();

is = httpEntity.getContent();

BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));

StringBuilder sb = new StringBuilder();

String line = null;

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

sb.append(line + "\n");

}

is.close();

json = sb.toString();

return new JSONObject(json);

總結(jié)

以上是生活随笔為你收集整理的android php mysql json 查询_android php mysql json的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。