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

后端 未结 3 924
耶瑟儿~
耶瑟儿~ 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:44

    according to the following posts from MySQL

    http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html http://dev.mysql.com/doc/refman/5.0/en/charset-applications.html

    your settings are not completely right i.e.

    use

     [mysqld]
     character-set-server=utf8
     collation-server=utf8_general_ci
    

    instead of

     [mysqld]
     default-character-set=utf8
    

    for the client I only found

     [mysql]
     default-character-set=utf8
    

    not

     [client]
     default-character-set=utf8
    

    try and give me some feedback.

    I can remember that I once read about a setting var to switch off the ability for a client to change the character setting. But I can't find the ref in mysql documentation now. If I find it I let you know.

    Hope that helps.

    Regards

    UPDATE

    @Unisland BTW I found this thread http://www.webmasterworld.com/php/3553642.htm where a similar problem is discussed

    Try either

    So you may try to add a:
    [mysqld]
    init-connect='SET NAMES utf8'

    or

    [client]
    default-character-set=utf8

    [mysqld]
    character-set-server=utf8
    default-character-set=utf8
    default-collation=utf8_unicode_ci
    character-set-client = utf8

    to set this as a default for all connections, or start with these queries after your specific script connects to the database before sending other queries: SET NAMES utf8; SET CHARACTER_SET utf8;

提交回复
热议问题