SQLSTATE[HY000] [2019] Unknown character set issue

Hey all!!

Got this error and made edits to my DB credentials in file but nothing is working. Trying to figure where the error is within my code but not successful.

    <?php
    $dbservername="";
    $dbuser="";
    $dbpass="";
    $dbname="";
    $conn=mysqli_connect($dbservername,$dbuser,$dbpass,$dbname);

    class Relation {
      // (A) CONSTRUCTOR - CONNECT TO DATABASE
      private $pdo = null;
      private $stmt = null;
      public $error = "";
      function __construct () {
        try {
          $this->pdo = new PDO(
            "mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=".DB_CHARSET, 
            DB_USER, DB_PASSWORD, [
              PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
              PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
            ]
          );
        } catch (Exception $ex) { die($ex->getMessage()); }
      }

Help is greatly appreciated :blush:

The only thing I can think of is that isn’t set correctly, mine is always ‘;charset=utf8’,

1 Like

From your phpmyadmin panel, select SQL tab and run this command:

show character set like 'utf%';

This will show you all of the valid character sets allowed in your configuration of your server.
Your DB_CHARSET is set in Wordpress usually. Are you using WP? I suspect it is not correct!
Try replacing it ‘utf8’…

1 Like

Thank ya so very much :heart:

Not using WP…Im just using basic HTML and PHP. Not really much of a fan of CMS

Well, in that case what is inside of DB_CHARSET ? You need to see what that is.
Next thing, is just take that out and let the database use it’s default.
When you set up the database, did you use the defaults? If so, then don’t try to reset them.

1 Like

As an aside to all the above; don’t use utf8 in MySQL. Use utf8mb4.

3 Likes
Sponsor our Newsletter | Privacy Policy | Terms of Service