List data from db and create a json

Hello, i need to create a json file of many registers of database, i can get the data but i
can’t create the json file, i think is something wrong about the syntax

code is here

thank you

What’s the error? Is it that you’re not returning a response object?

Without trying to run it, I would suggest that you change this:

$conteudo = json_encode(['sucesso' => true, 'dados' => $dados]);


$conteudo = $response->withJson(['sucesso' => true, 'dados' => $dados]);

Also, I don’t know why you’re writing the JSON to a file (I’m assuming it’s for debugging?) but if one request generates different JSON to another, and the two requests come in around the same time, you may well end up looking at the wrong version. If you don’t need to write it to the file system, don’t. If you remove the fopen() and the fwrite(), does it work?

i have 2 websites in diferent hosts that have the same content, everytime one website gets new content, i have to do this work 2 times, i think the easiest way to do this, is to create a json file of the db in one server, and create a page to read this json in the other server.

thank you!

OK, but we still don’t know what the error is, so we don’t know what we’re fixing :slight_smile: Has my suggestion helped?