欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php獲取數(shù)據(jù)庫中數(shù)據(jù)的實(shí)現(xiàn)方法

 更新時間:2017年06月01日 07:52:17   投稿:jingxian  
下面小編就為大家?guī)硪黄猵hp獲取數(shù)據(jù)庫中數(shù)據(jù)的實(shí)現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

廢話不多說,直接上代碼

<?php 
header("Content-type:text/html;charset=utf-8");//字符編碼設(shè)置 
$servername = "localhost"; 
$username = "root"; 
$password = "root"; 
$dbname = "web"; 
 
// 創(chuàng)建連接 
$con =mysqli_connect($servername, $username, $password, $dbname); 
 
// 檢測連接 
 
  
$sql = "SELECT * FROM users"; 
$result = mysqli_query($con,$sql); 
if (!$result) {
  printf("Error: %s\n", mysqli_error($con));
  exit();
}
 
$jarr = array();
while ($rows=mysqli_fetch_array($result,MYSQL_ASSOC)){
  $count=count($rows);//不能在循環(huán)語句中,由于每次刪除 row數(shù)組長度都減小 
  for($i=0;$i<$count;$i++){ 
    unset($rows[$i]);//刪除冗余數(shù)據(jù) 
  }
  array_push($jarr,$rows);
}
echo $str=json_encode($jarr);//將數(shù)組進(jìn)行json編碼
?>

這是獲取完之后轉(zhuǎn)成json格式

以上這篇php獲取數(shù)據(jù)庫中數(shù)據(jù)的實(shí)現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論