JSON does not show up when I re-file

Asked

Viewed 46 times

0

I am developing a PHP API with Slim Framework, but when I require the class general it should make a query in the database and return me the data of this table in JSON.

This is the connection class with the database

<?php
$host = "localhost";
$usuario = "root";
$senha = "";
$bd_nome = "liceuapp";
$mysqli = new mysqli($host, $usuario, $senha, $bd_nome);

This is the class that does the query in the database and should return me the JSON of this table

<?php
$app->get('/comunicados/geral', function() {

    require_once('dbconnect.php');

    $query = "select * from geral";
    $result = $mysqli->query($query);

    while($row = $result->fetch_assoc()) {
        $data[] = $row;

    }
    if (isset($data)) {
        echo json_encode($data);
    }
});

However, when I call the URL api/communications/general the screen turns white, does not display the JSON of the requested table.

Help me out, please!

  • "The screen turns white" could mean that there was an error. Have you checked the logs? Do you really have records in this table (will you)? PHP is configured to display errors?

1 answer

0

Caio, maybe you need to find out first where the error occurs, try to include an echo in each line to see how far your application reaches.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.