测试数据在贵哥的编程之路资源里面
<?php $link=mysqli_connect('localhost','root','','a'); //然后是指定php链接数据库的字符集 mysqli_set_charset($link,'utf8'); if(empty($_POST['phone'])) { return "请输入手机号"; } if(empty($_POST['pwd'])) { return "请输入密码"; } $sql="select * from php_user where status=1 and phone=".$_POST['phone']."limit 0,1"; $result=mysqli_query($link,$sql);//运行sql if(mysqli_num_rows($result) > 0){ while($row = mysqli_fetch_assoc($result)) { $data[] = $row; } $json = json_encode(array( "resultCode"=>200, "message"=>"查询成功!", "data"=>$data ),JSON_UNESCAPED_UNICODE); //转换成字符串JSON echo($json); }else{ $json = json_encode(array( "resultCode"=>200, "message"=>"暂无数据", "data"=>'' ),JSON_UNESCAPED_UNICODE); //转换成字符串JSON echo($json); }