json_encode不断返回null

时间:2015-05-09 19:22:52

标签: php mysql json

我正在尝试使用MySql和php来输出json文件。我已经构建了查询和json_encode,它正在运行。尝试阅读论坛和文章,并尝试了各种不同的东西,但没有任何结果。我知道编码存在问题,但是尽管尝试了很多东西,它仍然会返回NULL。

以下是代码:

<?php require_once('Connections/db_con.php'); ?>
<?php
mysql_query('SET CHARACTER SET utf8');
$result = mysql_query("SELECT 
kkj_bsms_studies.studytext,
kkj_bsms_studies.id, 
kkj_bsms_studies.teacher_id, 
kkj_bsms_studies.studytitle, 
kkj_bsms_studies.studyintro,
kkj_bsms_studies.media_hours, 
kkj_bsms_studies.media_minutes, 
kkj_bsms_studies.media_seconds, 
kkj_bsms_teachers.teachername, 
kkj_bsms_mediafiles.server, 
kkj_bsms_mediafiles.`path`, 
kkj_bsms_mediafiles.filename, 
kkj_bsms_mediafiles.`size`, 
kkj_bsms_servers.server_path, 
kkj_bsms_folders.folderpath
FROM kkj_bsms_studies, kkj_bsms_teachers, kkj_bsms_mediafiles,
kkj_bsms_servers, kkj_bsms_folders
WHERE series_id = 8 AND kkj_bsms_teachers.id =kkj_bsms_studies.teacher_id AND  kkj_bsms_mediafiles.study_id = kkj_bsms_studies.id AND kkj_bsms_servers.id =     kkj_bsms_mediafiles.server AND kkj_bsms_folders.id = kkj_bsms_mediafiles.path");  

//Create an array
$json_response = array();

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

    $row_array['hour'] = $row['kkj_bsms_studies.media_hours'];

    //push the values in the array
    array_push($json_response,$row_array);
}
echo json_encode($json_response);

$error = json_last_error();
echo $error;
//Close the database connection
fclose($db);
?>

提前感谢您的帮助。

0 个答案:

没有答案