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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:26:34
Original
1062 people have browsed it

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

<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>
Copy after login
Copy after login

回复内容:

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

<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>
Copy after login
Copy after login

好好看看文档,json_decode() 是解析json字符串的,json_encode()才是把数组解析成json字符串

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template