Digger Posted October 20, 2023 Share Posted October 20, 2023 My web host has upgraded the server to PHP8.1 and MySql8 2 days ago and i am constantly getting this error PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers in /home/***/***/app/Helpers/Database.php on line 63 This was line 63 $instance = new self("$type:host=$host;dbname=$name;charset=utf8", $user, $pass); and this is what i was advised to change it $instance = new self("$type:host=$host;dbname=$name;default-character-set=utf8", $user, $pass); Sadly the error still persists Here in the class function its in public static function get($group = false) { // Determining if exists or it's not empty, then use default group defined in config $group = !$group ? [ 'type' => DB_TYPE, 'host' => DB_HOST, 'name' => DB_NAME, 'user' => DB_USER, 'pass' => DB_PASS, ] : $group; // Group information $type = $group['type']; $host = $group['host']; $name = $group['name']; $user = $group['user']; $pass = $group['pass']; // ID for database based on the group information $id = "$type.$host.$name.$user.$pass"; // Checking if the same if (isset(self::$instances[$id])) { return self::$instances[$id]; } try { // I've run into problem where // SET NAMES "UTF8" not working on some hostings. // Specifiying charset in DSN fixes the charset problem perfectly! $instance = new self("$type:host=$host;dbname=$name;charset=utf8", $user, $pass); $instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Setting Database into $instances to avoid duplication self::$instances[$id] = $instance; return $instance; } catch (PDOException $e) { //in the event of an error record the error to ErrorLog.html Logger::newMessage($e); Logger::customErrorMsg(); } } Its worked fine for the past 8 years until 2 days ago but i am now pulling mu hair out Any help or advice would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/317387-pdo__construct-server-sent-charset-255-unknown-to-the-client/ Share on other sites More sharing options...
mac_gyver Posted October 20, 2023 Share Posted October 20, 2023 try using utf8mb4 for the setting. utf8 is (was) an alias for utf8mb4, which i'm guessing is no longer valid. Quote Link to comment https://forums.phpfreaks.com/topic/317387-pdo__construct-server-sent-charset-255-unknown-to-the-client/#findComment-1612469 Share on other sites More sharing options...
Digger Posted October 20, 2023 Author Share Posted October 20, 2023 Ive tried $instance = new self("$type:host=$host;dbname=$name;default-character-set=utf8mb4", $user, $pass); and $instance = new self("$type:host=$host;dbname=$name;charset=utf8mb4", $user, $pass); but still getting the same error Quote Link to comment https://forums.phpfreaks.com/topic/317387-pdo__construct-server-sent-charset-255-unknown-to-the-client/#findComment-1612471 Share on other sites More sharing options...
mac_gyver Posted October 20, 2023 Share Posted October 20, 2023 upon searching, this is due to the MySql server reporting a value back to the client (php in this case) that php doesn't recognize for the character set setting. is this just an error that is getting logged or does it prevent the connection from being used? here's a bug report that suggests a work-around of setting a character-set-server value in the MySql's my.cnf - https://bugs.mysql.com/bug.php?id=85946 Quote Link to comment https://forums.phpfreaks.com/topic/317387-pdo__construct-server-sent-charset-255-unknown-to-the-client/#findComment-1612474 Share on other sites More sharing options...
kicken Posted October 20, 2023 Share Posted October 20, 2023 From a little searching, this seems like something that was a compatibility issue between older PHP versions and newer Mysql versions. Are you sure your code has been updated to run on PHP 8? Shouldn't be an issue on PHP 8 as far as I can tell. Unless you need to do something with your hosting control panel to update your PHP version, this is something that you might have to get your host's support involved in to get fixed. Quote Link to comment https://forums.phpfreaks.com/topic/317387-pdo__construct-server-sent-charset-255-unknown-to-the-client/#findComment-1612475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.