国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 贺州市| 德化县| 太康县| 和硕县| 登封市| 舞阳县| 巴中市| 前郭尔| 柳州市| 永登县| 延边| 正镶白旗| 崇州市| 西城区| 乌鲁木齐县| 县级市| 阿勒泰市| 宣武区| 时尚| 鹤峰县| 龙泉市| 新龙县| 峨边| 内黄县| 会宁县| 辽宁省| 岱山县| 苍梧县| 水城县| 孝感市| 东乡县| 鸡东县| 霍山县| 吉林省| 贵南县| 广河县| 和林格尔县| 黄石市| 永清县| 桦川县| 娱乐|