JSON returns null when trying to get information in the database via PHP

0

I'm trying to get information from the bank with php and pass it to JSON, but it always comes empty returns null and with no error.

[
    {
        "current_field": null,
        "field_count": null,
        "lengths": null,
        "num_rows": null,
        "type": null
    }
]

Below the PHP code:

<?php 

require 'conexao.php';

$temperatura = "SELECT * FROM estufas";

$resultado_temperatura = mysqli_query($conexao,$temperatura)or 
die(mysqli_error($conexao));

if (mysqli_num_rows($resultado_temperatura) > 0) {

    $dados[] = $resultado_temperatura;

    echo json_encode($dados, JSON_PRETTY_PRINT);
}

?>
    
asked by anonymous 29.04.2018 / 01:59

1 answer

0

I was able to solve it, the code looks like this:

<?php 

require 'conexao.php';

$array = array();

$resultado = "SELECT Temperatura_Estufa,Umidade_Estufa FROM estufas";

$res = mysqli_query($conexao,$resultado)or die(mysqli_error($conexao));

while ($rows = mysqli_fetch_assoc($res)) {
$dados[] = array('Temperatura_Estufa' => $rows['Temperatura_Estufa'],
                 'Umidade_Estufa' => $rows['Umidade_Estufa'],);
}    
echo json_encode($dados);
?>
    
29.04.2018 / 02:31