国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 建站經(jīng)驗 > 正文

php簡單實現(xiàn)查詢數(shù)據(jù)庫返回js-on數(shù)據(jù)

2019-11-02 15:47:09
字體:
供稿:網(wǎng)友

 示例代碼一:

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 32 33 34 35 36 37 // 設(shè)置返回json格式數(shù)據(jù) header('content-type:application/json;charset=utf8');   //連接數(shù)據(jù)庫 $link = mysql_connect("localhost", "root", "root") or die("Unable to connect to the MySQL!");   mysql_query("SET NAMES 'UTF8'");   mysql_select_db("jilinwula", $link) or die("Unable to connect to the MySQL!");   // 獲取分頁參數(shù) $page = 0 ; $pageSize = 3;   if(!is_null($_GET["page"])) { $page = $_GET["page"]; }   if(!is_null($_GET["pageSize"])) { $pageSize = $_GET["pageSize"]; }   // 查詢數(shù)據(jù)到數(shù)組中 $result = mysql_query("select username,password from userinfo limit " . $page . ", ". $pageSize ."");   $results = array(); while ($row = mysql_fetch_assoc($result)) { $results[] = $row; }   // 將數(shù)組轉(zhuǎn)成json格式 echo json_encode($results);   // 關(guān)閉連接 mysql_free_result($result);   mysql_close($link);

示例代碼二:

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 32 33 34 35 36
迅雷鋪電影下載[www.aikan.tv/special/xunleipu/]
37 38 39 40 41 42 43 44 45 46 <?php   //需要執(zhí)行的SQL語句 //單條 $sql="select id,name from tbl_user where id=1"; //多條數(shù)據(jù) //$sql="select id,name from tbl_user";   //調(diào)用conn.php文件進(jìn)行數(shù)據(jù)庫操作 require('Conn.php');   //提示操作成功信息,注意:$result存在于conn.php文件中,被調(diào)用出來 if($result) {   // $array=mysql_fetch_array($result,MYSQL_ASSOC);     /*數(shù)據(jù)集   $users=array(); $i=0; while($row=mysql_fetch_array($result,MYSQL_ASSOC)){   echo $row['id'].'-----------'.$row['name'].'</br>'; $users[$i]=$row; $i++;   } echo json_encode(array('dataList'=>$users));   */   /*單條數(shù)據(jù)*/   $row=mysql_fetch_row($result,MYSQL_ASSOC);   echo json_encode(array('jsonObj'=>$row)); }   mysql_free_result($result); //釋放結(jié)果 mysql_close(); //關(guān)閉連接   ?>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 镇安县| 湖口县| 竹溪县| 铁力市| 莆田市| 大安市| 曲阜市| 米林县| 上饶县| 镇雄县| 原平市| 贞丰县| 石家庄市| 佛学| 和政县| 武强县| 渑池县| 平江县| 濉溪县| 双鸭山市| 陕西省| 东乡族自治县| 石景山区| 阳谷县| 河西区| 平原县| 卓尼县| 大港区| 阿城市| 新丰县| 龙陵县| 全州县| 达拉特旗| 古丈县| 裕民县| 华阴市| 南和县| 武城县| 黔西县| 突泉县| 朔州市|