明明数据库能找到数据,为什么返回的json里面data全是null?

图片说明

switch ($getType) {
            case "1":
                $data = array();
                $sql = "SELECT songId, songName, singerName, songAlbum, albumName FROM web_songsinfo, web_singersinfo, web_albumsinfo WHERE songName LIKE '%" . $getKeywords . "%'";
                $result = $conn->query($sql);
                if ($result) {
                    $code = 1;
                    $message = "success";
                    $songInfo = new SongInfo();
                    while ($resultRow = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
                        $songInfo->songId = $resultRow["songId"];
                        $songInfo->songName = $resultRow["songName"];
                        $songInfo->songSinger = $resultRow["singerName"];
                        $songInfo->albumId = $resultRow["songAlbum"];
                        $songInfo->albumName = $resultRow["albumName"];
                    }
                    $data[] = $songInfo;
                    mysqli_free_result($result);
                } else {
                    $code = 2;
                    $message = "failed";
                    $data = '';
                }
                break;
            case "10":
                break;
            case "100":
                break;
        }
        mysqli_close($conn);
        $response = new searchResponse;
$response->search($code, $message, $data);

response.php:

class searchResponse
{
    public function search($code, $message, $data)
    {
        $result = array(
            "code" => $code,
            "message" => $message,
            "data" => $data
        );
        echo json_encode($result, JSON_UNESCAPED_UNICODE);
    }
}

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问