2
I have a problem in the return JSON of some information from my BD, some are accentuating and the answer fails, I have tried some past suggestions, such as this:
$response = utf8_encode($response);
But it didn’t, what I have is this:
if(isset($_POST['Historico']) && isset($_POST['Historico']) != "") {
$IdHistorico = $_POST['Historico'];
// ÁREAS x EXPECTATIVA
$sqlHistoricoProfissional = "SELECT
IdHistorico,
IdCandidato,
Empresa,
Cargo,
date_format(crrHistoricoProfissional.DataEntrada, '%d/%m/%Y') AS DataEntrada,
date_format(crrHistoricoProfissional.DataSaida, '%d/%m/%Y') AS DataSaida,
UltimoSalario,
Atividades
FROM crrHistoricoProfissional WHERE IdHistorico = ?";
$stm = $conexao->prepare($sqlHistoricoProfissional);
$stm->bindValue(1, $IdHistorico, PDO::PARAM_INT);
$stm->execute();
$sqlHistoricoProfissional = $stm->fetchAll(PDO::FETCH_OBJ);
// CONTAGEM DE REGISTROS RETORNADOS
$ContReg = count($sqlHistoricoProfissional);
// FECHANDO A CONSULTA
$stm->closeCursor();
$response = array();
if($ContReg > 0) {
foreach ($sqlHistoricoProfissional as $DadosReg) {
$response = $DadosReg;
// $response = utf8_encode($response);
//var_dump($row);
}
} else {
$response['status'] = 200;
$response['mensagem'] = "Não foram encontrados registros";
}
// display JSON data
echo json_encode($response);
} else {
$response['status'] = 200;
$response['mensagem'] = "Requisição inválida";
}
My connection is like this:
define('HOST', 'localhost');
define('USER', 'xxxxxxx');
define('PASSWORD', 'xxxxxxx');
define('DBNAME', 'xxxxxxx');
define('TYPEDB', 'mysql');
define('CHARSET', 'utf8');
The Bank is like this:
COLLATE='utf8_general_ci' ENGINE=InnoDB
tried it like this ?
json_encode($response, JSON_UNESCAPED_UNICODE);– Mateus
Hello @Matthew, already but not in this format, it was perfect, thank you very much, as I can give an acceptance?
– adventistapr