使用php从mysql数据库中获取Json

时间:2018-03-31 15:48:30

标签: php mysql

我获取的代码值小于255,但如果列中的值大于255,则不会返回。

<?php
    include 'dbconfig.php';
    $conn = new mysqli($servername, $username, $password, $dbname);
    if($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    $sql = "SELECT * FROM news ORDER BY id DESC";
    $result = $conn->query($sql);
    if($result->num_rows >0){
        while($row[] = $result->fetch_assoc()) {
            $tem = $row;
            $json = json_encode($tem); 
        }
    }else {
        echo "0 results";
    }
    echo $json;
    $conn->close();
?>

1 个答案:

答案 0 :(得分:0)

将您的代码更改为:

  t.string :category_name
  t.string :status