I have a webservice in PHP with MySQL database and getting answers in JSON. It is working normally, but I have a problem using the following query:
SELECT podcast.id, podcast.nome, podcast.descricao, autor.nome, categoria.nome_cat
FROM podcast
JOIN autor ON autor.id = podcast.autor_id
JOIN categoria ON categoria.id = podcast.categoria_id;
I tested the above query in MySQL and it works.
Below is the webservice code:
<?php
/*
* Following code will list all the podcasts
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all podcasts from podcasts table
$result = mysql_query("SELECT podcast.id, podcast.nome, podcast.descricao, autor.nome_autor, categoria.nome_cat FROM podcast
JOIN autor ON autor.id = podcast.autor_id
JOIN categoria ON categoria.id = podcast.categoria_id;
") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// podcast node
$response["podcast"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$podcast = array();
$podcast["id"] = $row["id"];
$podcast["nome"] = $row["nome"];
$podcast["descricao"] = $row["descricao"];
$podcast["nome_cat"] = $row["nome_cat"];
$podcast["nome_autor"] = $row["nome_autor"];
// push single podcast into final response array
array_push($response["podcast"], $podcast);
}
// echoing JSON response
echo json_encode($response);
} //else {
// no podcasts found
//$response["success"] = 0;
//$response["message"] = "No podcasts found";
// echo no users JSON
//echo json_encode($response);
//}
?>
The Query that I quoted at the beginning of the post does not show any response in JSON, with the following message:
Response does not contain any data.
I've done some tests and it's happening in both 'if' and 'while'. If I print the response on the screen using print_r, I get the information I'd like.
Could anyone help me?