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

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

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

廢話不多說(shuō),直接上代碼

<?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); 
 
// 檢測(cè)連接 
 
  
$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)語(yǔ)句中,由于每次刪除 row數(shù)組長(zhǎng)度都減小 
  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ù)庫(kù)中數(shù)據(jù)的實(shí)現(xiàn)方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論