Does not show JSON PHP object

0

I want to show the result of the query in a JSON but it gives me an empty result, I suspect it is by SCOPE DE PHH, but I have not been able to solve it.

<?php
include('datos_bd.php');

$conectar = mysqli_connect($nombre_host, $nombre_usuario, $contrasena_usuario, $nombre_bd);

if ($conectar) {
$consulta ="SELECT * FROM casas";
if ($resultado=$conectar->query($consulta)) {
    while ($fila=$resultado->fetch_row()) {
        $id=$fila[0];
        $nombre=$fila[1];
        $codigo=$fila[2];
        $precio=$fila[3];
        $descripcion=$fila[4];
        $datos[]=array('id'=>$id,'nombre'=>$nombre,'codigo'=>$codigo,'precio'=>$precio,'descripcion'=>$descripcion);
        $datos_json = json_encode($datos);
    }
    echo $datos_json;
 }
}
    
asked by Javier 20.12.2018 в 03:13
source

0 answers