Mysqli does not return results

Asked

Viewed 79 times

0

Colleagues.

I want to bring results from a mysql table, but it’s not working. What is causing me strangeness is that when the information has accents, it does not work, and in the database the accents are correct. See:

include("includes/conexao.php"); // Faço a conexão

$escola = htmlentities(filter_input(INPUT_POST,"BuscarEscola"));
$escolaSeguro = mysqli_real_escape_string($con,$escola);

$sqlEscolas = mysqli_query($con,"SELECT * FROM escolas WHERE nome = 'Colégio Inclusão';");
$jmEscolas = mysqli_fetch_object($sqlEscolas);
echo "Nome " .$jmEscolas->nome;
  • What is the engine from your database ?

  • 1

    In short, you have to make sure that all the encodings of your stuff are in the same pattern starting with the code editor. More details in the answers to the linked question above.

  • In the case of accent the bd charset has to be Unicode tb. But why are you using the operator = in a name search? It would not be more logical to use like '%College Inclusion%'?

  • 1

    @Norivanoliveira if he wants an exact search, the LIKE doesn’t make sense. In fact, what I see of people using LIKEwhere no need here on the site is absurd. Besides being terrible, because LIKE with joker at the beginning does not avail index.

1 answer

-1

Set UTF8 in your project.

In the HTML header itself of your documents you can do this. See:

<meta charset="utf-8" />

However, it is not 100% of the time that the server accepts this HTML statement and continues to "deface" special characters.

In cases like this, instead of setting the encoding by the HTML header, define by the php ini_set function.

<?php
ini_set('default_charset','UTF-8');
?>
  • Colleagues, I solved as follows: mysqli_set_charset($con,"utf8").

Browser other questions tagged

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