Home >Backend Development >PHP Tutorial >php将数据库查询的结果打印成json格式,怎么做

php将数据库查询的结果打印成json格式,怎么做

WBOY
WBOYOriginal
2016-06-06 20:26:341023browse

这是我的代码,输出有问题的那句我标注了。

<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字符串

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn