I'm experiencing a problem developing a project where I can't put accented characters.
I'm 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 UTF-8 encoded, as shown in the image below:
NOTE: I use VsCode.
All PHP files that are pages, have the charset meta set to utf-8, as shown in the image below:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
My database is configured for utf8, as shown in the image below:
The tables are configured with the utf8 charset, as shown in the image below:
The columns are configured with the utf8 charset, as shown in the image below:
NOTE: I added the "NOT NULL" rule to ignore tables that do not have a charset configuration.
When executing the query to include the information in the database, I run 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);
NOTE: at the top of the file I include the configuration file that contains the information shown in the first image.
After performing this operation, the database shows the information as follows:
When viewing the information on the website, it appears as follows:
The original text being this:
I managed to make it work by adding the "setCharset" before giving the "execute" in the query, as shown in the image 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);
Achieving the following result in MySQL:
I would like to understand where I am going wrong. I'm trying to make utf8 "automatic" without having to call "setCharset" before any kind of query execution.
I appreciate any kind of help. :)
NOTE: if you need more information about the process to better understand the problem, just let me know.