1
It was with an API returning the data correctly, but it stopped out of nowhere.
The SQL statement when executed in Wrockbrench works. Other Apis follow this same pattern as below. But it is not returning. And I was returning before, I do not know what I changed that shows nothing of the result. Follow the codes:
My DAO:
<?php
class MensagemDAO {
private $conexao;
public function __construct() {
$this->conexao = new Conexao();
}
public function consultarMensagens() {
$sql = "SELECT * FROM mensagens WHERE enviado = 1";
$resultado = mysqli_query($this->conexao->getCon(), $sql);
if (mysqli_num_rows($resultado) > 0) {
return $resultado;
} else {
return false;
}
}
public function consultarCodigo($codigo) {
$sql = "SELECT * FROM mensagens WHERE idmensagens = '$codigo'";
$resultado = mysqli_query($this->conexao->getCon(), $sql);
if (mysqli_num_rows($resultado) > 0) {
return $resultado;
} else {
return false;
}
}
public function consultarPremioMes() {
$sql = "SELECT * FROM premio_mes WHERE NOW() >= data_inicio AND NOW() <= data_fim";
$resultado = mysqli_query($this->conexao->getCon(), $sql);
if (mysqli_num_rows($resultado) > 0) {
return $resultado;
} else {
return false;
}
}
}
?>
My JSON Return API:
<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
// header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
}
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
}
exit(0);
}
header('Content-type: application/json');
include "./../Classes/Conexao.php";
include './../Classes/DAO/MensagemDAO.php';
$MensagemDAO = new MensagemDAO();
$consulta = $MensagemDAO->consultarMensagens();
if ($consulta == true) {
for ($i = 0; $i < mysqli_num_rows($consulta); $i++) {
$linha = mysqli_fetch_array($consulta);
$respostas [] = array(
'idmensagens' => $linha['idmensagens'],
'subject' => $linha['subject'],
'message' => $linha['message'],
'enviado' => $linha['enviado']
);
}
}else{
echo 'sem resultado';
}
echo json_encode($respostas);
?>
Follows the structure of the table:
What am I doing wrong?
There is no code versioning to see the latest file changes?
– fernandosavio
The importance of a version control my friend!
– rbz
@fernandosavio posted without seeing your comment...rs
– rbz
That’s when the VCS shines
– fernandosavio
It was an accentuation problem....
– Ramos