Getting data from MYSQL into JSON using PHP

后端 未结 5 519
挽巷
挽巷 2021-02-02 03:54

I have the following quite simple test PHP code that extracts the data and puts it into JSON formatted text.

I get the following error..

Fatal err

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 04:15

    Use this one:

    $result = mysql_query("SELECT * FROM listinfo");
    
    $json = array();
    $total_records = mysql_num_rows($result);
    
    if($total_records > 0){
      while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
        $json[] = $row;
      }
    }
    
    echo json_encode($json);
    

提交回复
热议问题