Luís Aurélio Luís Aurélio - 3 months ago 39
PHP Question

UTF-8 X MariaDB on XAMPP

I have a problem with MariaDB on XAMPP (no matter if you are running on Windows or Linux).
I am using XAMPP with PHP 7 (initially I used a XAMPP 5.6 on Xubuntu and the same problem occurs) in Windows 10 as my site development server. I set it:

  • The meta tag has UTF-8 in all HTML archives,

  • The PHP header function to send UTF -8 data,

  • The PHP directives, when I connect to the DB (I use MySQLi)

  • mysqli_set_charset($conexao, "utf-8");
    setlocale(LC_ALL, 'pt_BR.utf8');

  • The default_coding on php.ini is setted for UTF_8,

  • And all the database is set in utf8_general_ci collation.

I used phpMyAdmin embedded in XAMPP to enter test data ,in the first test was creating fields in phpMyAdmin itself, in the second test used the feature to export data from a CSV file (the file has been set to UTF-8 encoding).

What happens is that when I try to make a query to the database and then try to display the data obtained from this query, accented characters are all with question marks, forcing to treat the information obtained from the database with the function utf8_encode.

I do not bother with it at the time, but when transferred my site to the production server (not XAMPP), the data coming from the database and treated with utf8_encode function were displaying (in all browsers) in place of those accented characters only question marks (?) and exclamations (!). I had to take the calls utf8_encode and solved the problem.

In both servers submitted the same SQL file and eventually occurring this difference in operation . The only difference is that the production server phpMyAdmin did not accept the following header of my SQL file:

/*!40101 SET NAMES utf8mb4 */

Here are the server settings:
XAMPP deployment server:

  • PHP 7.0.4

  • MariaDB 10.1.10

  • phpMyAdmin 4.5.1

Production server:

  • PHP 7.0.4

  • phpMyAdmin

  • MariaDB 10.0.24

Please help me!

Kind regards,



a) mysqli_set_charset() can fail for various reasons, therefore: add error handling, e.g.

if ( !mysqli_set_charset($conexao, "utf-8") ) {
  throw new mysqli_sql_exception('changing charset failed');

b) try again with utf8 instead of utf-8