davy_yg's avatar
Level 27

mysqli_real_connect(): Server sent charset (255) unknown to the client

One of my old project is on php 5.6.4, after installing the XAMPP web server and trying to run my project, I got the following errors:

MySQL said: Documentation Cannot connect: invalid settings. mysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers mysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers Connection for controluser as defined in your configuration failed. mysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers mysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers

Any idea why?

I tried the following solutions but it didn't work out.

ref: https://stackoverflow.com/questions/43437490/pdo-construct-server-sent-charset-255-unknown-to-the-client-please-rep

0 likes
1 reply
LaryAI's avatar
Level 58

The error you're encountering, mysqli_real_connect(): Server sent charset (255) unknown to the client, typically occurs when the MySQL server is using a character set that the MySQL client library does not recognize. This can happen due to a mismatch between the MySQL server version and the MySQL client library version.

Here are a few steps you can take to resolve this issue:

  1. Update MySQL Client Library: Ensure that your MySQL client library is up to date. Since you are using PHP 5.6.4, you might be using an older version of the MySQL client library. Updating it to a more recent version might resolve the charset issue.

  2. Set the Character Set Manually: You can explicitly set the character set for the MySQL connection in your PHP code. This can be done using the mysqli_set_charset() function.

Here is an example of how you can set the character set manually:

$mysqli = new mysqli("localhost", "username", "password", "database");

// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Set the desired character set
if (!$mysqli->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
    printf("Current character set: %s\n", $mysqli->character_set_name());
}

// Your query and other operations go here

$mysqli->close();
  1. Check MySQL Server Configuration: Ensure that your MySQL server is configured to use a character set that is supported by your MySQL client library. You can check the default character set of your MySQL server by running the following query:
SHOW VARIABLES LIKE 'character_set_server';

If the character set is not utf8 or another common character set, you might want to change it in your MySQL server configuration file (my.cnf or my.ini).

  1. Upgrade PHP and MySQL: If possible, consider upgrading to a more recent version of PHP and MySQL. PHP 5.6.4 is quite old and may not be fully compatible with newer versions of MySQL. Upgrading to a more recent version of PHP (e.g., PHP 7.x or 8.x) and MySQL can help avoid such compatibility issues.

By following these steps, you should be able to resolve the charset issue and establish a successful connection to your MySQL database.

Please or to participate in this conversation.