json_encode()拒绝两个MySQL列


json_encode() rejects two MySQL columns

我正在尝试使用PHP和AngularJS在HTML页面中显示数据。以下是PHP代码:

<?php
$mysqli = mysqli_connect("localhost", "root", "admin", "webstore");
if(mysqli_connect_errno()){
    printf("Connect failed: %s'n", mysqli_connect_error());
    exit();
}
$output = array();
$json = array();
$result = mysqli_query($mysqli, 'SELECT * FROM products');
while($row = mysqli_fetch_assoc($result)) {
    $output = array(
        'id'=>$row['id'],
        'code'=>$row['product_code'],
        'image'=>$row['product_image'],
        'price'=>$row['price']
        
    );
  array_push($json, $output);    
}
header('Content-Type: application/json');
echo json_encode($json);
?>

这是controller.js 的代码

controller('MainController', function($scope,$http) {
    $http.get('prod.php').success(function(response){
        $scope.items = response;
        console.log(response);
    });

因此,所有内容都很好地显示在我的HTML页面上,但当我添加到数组时

$row['name'] && $row['description']

CCD_ 1和CCD_。然而,如果我只写print_r($json),它会打印正确的结果。

所以我不知道json_encode()为什么不接受这两列。任何帮助都会很好。

更新

所以为了清楚起见,我尝试添加$row['name']&amp;$row['description']转换为$output数组,同时查看查询结果。所以它会是这样的:

$output = array(
    'id'=>$row['id'],
    'code'=>$row['product_code'],
    'image'=>$row['product_image'],
    'price'=>$row['price'],
    'name'=>$row['name'],
    'description'=>$row['description']
);

但正如我所说,由于某种原因,这并不奏效。

我的数据库表的结构如下:

+-------------------------------------+
| id            | int(11) primary key |
| product_code  | varchar(50)         |
| name          | varchar(50)         |
| description   | text                |
| price         | double              |
| product_image | varchar(50)         |
+-------------------------------------+

我通过添加解决了这个问题

mysqli_set_charset('utf8)

现在一切都显示正确:

<?php
$mysqli = mysqli_connect("localhost", "root", "admin", "webstore");
if(mysqli_connect_errno()){
    printf("Connect failed: %s'n", mysqli_connect_error());
    exit();
}
$output = array();
$json = array();
$result = mysqli_query($mysqli, 'SELECT * FROM products');
while($row = mysqli_fetch_assoc($result)) {
    $output = array(
        'id'=>$row['id'],
        'code'=>$row['product_code'],
        'image'=>$row['product_image'],
        'price'=>$row['price']
    );
    array_push($json, $output);   
}
mysqli_set_charset('utf8);
header('Content-Type: application/json');
echo json_encode($json);
?>