UTF-8 does not work when entering data

Asked

Viewed 272 times

0

I use utf-8 at the time of insertion of the field nome in PHP, thus:

$nome = utf8_encode(strtolower($nome));

When checking how the insert Before inserting, the word is correct, but when I access the bank after insertion, the word is disfigured. I’d like to know what I’m doing wrong, because I’ve tried to change in the bank to utf-8 and yet you insert it wrong.

Thank you in advance!

  • In connection with Mysql you have set to use UTF8?

  • In your case change the constant MB_CASE_UPPER for MB_CASE_LOWER. strtolower() does not work with characters with more than one byte (usually accents and others). If Encode is right you can also remove the utf8_encode()

  • MB_CASE_LOWER returns error: Fatal error: Call to Undefined Function MB_CASE_LOWER(). And I didn’t understand you, if the Ncode was right, remove the Ncode?

  • $nome = mb_convert_case($nome, MB_CASE_LOWER); didn’t work? It was wrong for the bank yet?

  • 1

    Can’t the connection be the problem? I use utf8 in my projects: $con = new PDO('mysql:host=127.0.0.1;dbname=test', 'root','123456',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

  • Provides the code you use for connection to the bank and checks if your files are in utf8

  • SET NAMES utf8 should work

  • I will test all this and return here with the result

  • 2

    One of the first problems I notice in the code is utf8_encode. This is a compatibility function with external systems, if the DB and the output are in the same pattern, it makes no sense. More than that: strtolower is not a multibyte function. It should be mb_.... (unless you are ACTUALLY converting patterns)

Show 4 more comments

1 answer

0


Through the comments I researched how to do set names with mysqli and stayed like this:

mysqli_query($conexao, "set names 'utf8'");

Correctly inserted seat seats.

Browser other questions tagged

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