I need to take data from the database and display in JSON but gives error

Asked

Viewed 151 times

0

I am using SLIM PHP to develop an API. The class that takes information from the database to display in JSON does not work!

I access this local host, which I created: api/communications/general

The general is a class that contains this code:

<?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_enconde($data);
    }
});

However, she makes this mistake every time she is called: Slim Application Error

A website error has occurred. Sorry for the Temporary inconvenience.

I don’t know what happens, please someone can help me solve?

1 answer

0


json_enconde there is no!

json_encode is correct.

  • That was it, how could I not see... Now there is no error, but when I run the general it does not come the table information in JSON, on the screen appears nothing

  • You have to go trial. Without having access to your data there is no way to know what is wrong. Go echo to find out where the error is. Although I’ve never used echo with slim framework, I’ve always used "Return Response", I don’t even know if echo works....

Browser other questions tagged

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