a permanent way of doing mysqli->set_charset()?

后端 未结 3 956
耶瑟儿~
耶瑟儿~ 2021-02-04 06:20

after setting all config file and runtime options for charset that i can find to utf-8, new mysqli connections made with php still has its charset set to latin1, which effective

3条回答
  •  青春惊慌失措
    2021-02-04 06:56

    I know this is a very old thread, but I just encountered this issue on my Fedora 30 KDE laptop after installing MariaDB (and have spent over an hour looking for the answer). On my Ubuntu 18.04 server, everything just works without having to modify any config files, but on my laptop running Fedora 30 KDE, I had to:

    $ sudo vi /etc/my.cnf.d/client.cnf
    

    and then added default-character-set in the [client-mariadb] section:

    [client-mariadb]
    default-character-set = utf8mb4
    

    I had to do the same for the server config:

    $ sudo vi /etc/my.cnf.d/mariadb-server.cnf
    

    and then added the following in the [mysqld] section:

    [mysqld]
    character-set-server  = utf8mb4
    collation-server      = utf8mb4_general_ci
    

    Then just restart MariaDB:

    $ sudo systemctl restart mariadb.service
    

    After this, there's no need to explicitly set the character set within PHP scripts.

提交回复
热议问题