1
Hello guys :D
I’m going through a problem developing a project where I can’t put accented characters.
I am using to make the connection to the Mysql database, Adodb in version 5.20.14.
I have a main configuration file where the connection is set as follows:
$s_driver = "mysqli";
$o_db = adoNewConnection($s_driver);
$o_db->connect($s_dbhost,$s_dbuser,$s_dbpasswd,$s_dbname);
$o_db->SetFetchMode(ADODB_FETCH_ASSOC);
$o_db->setCharset("utf8");
All files developed are with UTF-8 encoding, as shown below:
OBS: I use the Vscode.
All PHP files that are pages, are with the charset meta set as utf-8, as image below:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
My database is set to utf8, as shown below:
Tables are configured with the utf8 charset, as shown below:
The columns are configured with the utf8 charset, as shown below:
OBS: added the "NOT NULL" rule to ignore tables that do not have the charset setting.
When executing the query to include the information in the database, I run it as follows:
$s_query_incluir = "INSERT INTO agtb_ordensdeservicos(id_agenda,
id_empresa,
hora_ini,
hora_fim,
observacoes,
tipo,
csa)
VALUES('".$a_post['add_id_os_dt_agenda']."',
'".ID_EMP_ATUAL."',
'".$a_post["add_os_hora_ini"]."',
'".$a_post['add_os_hora_fim']."',
'".$a_post['add_observacao']."',
'".$a_post['add_os_tipo']."',
'".$a_post['add_os_csa']."');";
$o_db->execute($s_query_incluir);
OBS: at the top of the file I do the include of the configuration file that contains the information shown in the first image.
After performing this operation, the database displays the information thus:
When viewing the information on the site, appears as follows:
Since the original text is this:
I was able to make it work by adding the "setCharset" before giving the "execute" in the query, as shown below:
$s_query_incluir = "INSERT INTO agtb_ordensdeservicos(id_agenda,
id_empresa,
hora_ini,
hora_fim,
observacoes,
tipo,
csa)
VALUES('".$a_post['add_id_os_dt_agenda']."',
'".ID_EMP_ATUAL."',
'".$a_post["add_os_hora_ini"]."',
'".$a_post['add_os_hora_fim']."',
'".$a_post['add_observacao']."',
'".$a_post['add_os_tipo']."',
'".$a_post['add_os_csa']."');";
$o_db->setCharset("utf8");
$o_db->execute($s_query_incluir);
Getting the following result in Mysql:
I’d like to understand where I’m going wrong. I am trying to leave utf8 "automatic" without I need to get called "setCharset" before any kind of query execution.
I appreciate any kind of help. :)
OBS: if you need more information about the process to better understand the problem, just let me know.
What is the result of the query in the terminal? Also with encoding error?
– Mauro Rocha
You mean in the query? I put in the main file a query with a "select" test and the character "is" is displayed normally on the screen. Running this same query in Mysql Workbench, the character "is" is presented as "Ã". If I go to the Workbench itself and change this "À" record to "is" and query in PHP, it gets the character as "?".
– Allan Cabral
Have you tried inserting a line with PHP strings into the database without using $_POST content? Also try to treat the content that came from $_POST using the utf8_decode function().
– wensiso
@wensiso, In the file that makes the inclusion of the information in the BD and that receives the contents of $_POST, I created a variable for testing putting as content the "is" and includes in the BD. It appears as "Ã". If I use the "utf8_encode" in the information received, in the database it appears as "Â". If I use "utf8_decode", the "is" appears correctly in the BD. As far as I could tell, the information is coming into the database as something other than "UTF-8", so the "is" appears as "IS". If I change the "Ã" by "is" directly in the BD, in PHP the value query appears normal as "is".
– Allan Cabral