PHP MYSQL 增刪改查之list JsonList

來源:互聯網
上載者:User

標籤:close   res   list   state   工程師   pre   ==   讀取   網站   

<?php//header("Content-type: text/html; charset=UTF8");//header("Content-Type: text/html;charset=utf-8"); /*$d = $_POST[‘test‘];if($d==‘testgaga‘)    echo ‘Success_1!‘;else    echo ‘Fail_1‘;*/$mysql_server_name=‘127.0.0.1‘; //改成自己的mysql資料庫伺服器$mysql_username="root"; //改成自己的mysql資料庫使用者名稱$mysql_password="qmtg"; //改成自己的mysql資料庫密碼$mysql_database="testmydatabase"; //改成自己的mysql資料庫名$conn=new mysqli($mysql_server_name,$mysql_username,$mysql_password); //串連資料庫if($conn==false){    #echo "資料連線失敗!";}else{    #echo "資料連線成功!";} $conn->query("set names ‘utf8‘"); //資料庫輸出編碼 應該與你的資料庫編碼保持一致.南昌網站建設公司百恒網路PHP工程師建議用UTF-8 國際標準編碼.$conn -> select_db($mysql_database); //開啟資料庫$sql ="select * from testtale"; //SQL語句$result = $conn->query($sql); //查詢成功//test success one$end=array();$end[‘state‘]=‘1‘;$arr = array(); // 輸出每行資料  while($row = $result->fetch_assoc()) {      $count=count($row);//不能在迴圈語句中,由於每次刪除row數組長度都減小      for($i=0;$i<$count;$i++)    {          unset($row[$i]);//刪除冗餘資料      }      array_push($arr,$row);      $end[‘list‘]=$arr;}   //echo json_encode($arr,JSON_UNESCAPED_UNICODE);//json編碼  echo json_encode($end,JSON_UNESCAPED_UNICODE);//json編碼  $conn->close();  /*while($rows =$result->fetch_array()){//可以直接把讀取到的資料賦值給數組或者通過欄位名的形式賦值也可以//$array[] = $rows;//$array[$rows[‘id‘]] = $rows;}//print_r($array);//最後通過json_encode()轉化數組echo json_encode($array);*/?>

 

PHP MYSQL 增刪改查之list JsonList

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.