<?php header("Content-type:text/html;charset=utf-8"); $mysqli=new mysqli('localhost','root',''); mysqli_select_db($mysqli,'mytest'); $sql="select * from message"; $res=$mysqli->query($sql); $arr=array(); while ($row=$res->fetch_assoc()) { $arr[]=$row; } $res->free(); //关闭连接 $mysqli->close(); echo(json_encode($arr));//这里用echo而不是return ?>