Home >Backend Development >PHP Tutorial >php将数据库查询的结果打印成json格式,怎么做
这是我的代码,输出有问题的那句我标注了。
<code class="php"> $conn = mysqli_connect("localhost:3306", "root", "19961120"); if($conn){ mysqli_select_db($conn, "test"); $result = mysqli_query($conn, "select * from user"); $users = array(); for($i=0;$i<mysqli_num_rows mysqli_fetch_row var_dump></mysqli_num_rows></code>
这是我的代码,输出有问题的那句我标注了。
<code class="php"> $conn = mysqli_connect("localhost:3306", "root", "19961120"); if($conn){ mysqli_select_db($conn, "test"); $result = mysqli_query($conn, "select * from user"); $users = array(); for($i=0;$i<mysqli_num_rows mysqli_fetch_row var_dump></mysqli_num_rows></code>
好好看看文档,json_decode() 是解析json字符串的,json_encode()才是把数组解析成json字符串