Good day. I come to you again with my Cyrillic alphabet. There are two options for the code:

$utfquery = "SET NAMES utf8 COLLATE utf8_unicode_ci; SET CHARACTER SET utf8"; $utf8 = mysqli_query($link, $utfquery); 

and number two:

 $utfquery = "SET NAMES utf8 COLLATE utf8_unicode_ci; SET CHARACTER SET utf8"; $utf8 = mysql_query($utfquery); 

The first case does not take off. In contrast to the good old second ((Record 24 июня , inserted by the script, in the first case looks like this: 24 июнÑ

The base and table encoding is utf8. The script encoding is also utf8, installed via mb_internal_encoding("utf-8") . Thank you in advance for your help.

    1 answer 1

    Both ways should not be used - the library of access to mysql must know the encoding used in order to correctly transfer and screen data. Use the encoding challenge to set:

     $mysqli->set_charset('utf8'); 

    For PDO , this is the charset parameter in DSN :

     $pdo = new PDO("mysql:host=localhost;dbname=world;charset=utf8", 'my_user', 'my_pass'); 

    By the way,

    The script encoding is also utf8, installed via mb_internal_encoding ("utf-8")

    mb_internal_encoding not related to the script encoding. Specifies the default encoding in the last parameter of the mb_* functions.

    • I correctly understand that in the procedural form it should look like mysqli_set_charset($link, 'utf8'); ? - Anton Foigt
    • Yes, it seems like that. - Petty