小编典典

无法将俄语文本插入mysql数据库

mysql

当我尝试将俄语文本插入MySQL数据库时,它会像这样插入:г??????????????? ?? ?????????
Рісѓрїр°ріс‹рїр°с‹рір°рї

因此,我有两个页面:registration.php和addUser.php。在每个

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

数据库由11个表组成,每个表都有排序规则:utf8_general_ci,类型:MyISAM。每个表中的每个字段都具有排序规则:utf8_general_ci。

当我直接在phpMyAdmin中写数据库时,然后将此数据显示到网页上。用英语和俄语-都可以。

但是,当我填满表格后,在registration.php上包含个人数据,然后去addUser.php-所有俄语字符都像我写上一样显示在页面上和数据库中。

    function AddNewUser($Name, $Surname, $FatherName, $Email, $Password, $Phone, $DegreeID, $RankID, 
$Organization, $Department, $Country, $City, $Address, $Job)
{
        //fetch data from database for dropdown lists
        //connect to db or die)
    $db = mysql_connect($GLOBALS["gl_kussdbName"], $GLOBALS["gl_kussUserName"], $GLOBALS["gl_kussPassword"] ) or die ("Unable to connect");

    //to prevenr ????? symbols in unicode - utf-8 coding
    mysql_query("SET NAMES 'UTF8'");

    //select database
    mysql_select_db($GLOBALS["gl_kussDatabase"], $db);
    $sql = "INSERT INTO UserDetails (
UserFirstName,
UserLastName,
UserFatherName,
UserEmail,
UserPassword,
UserPhone,
UserAcadDegreeID,
UserAcadRankID,
UserOrganization,
UserDepartment,
UserCountry,
UserCity,
UserAddress,
UserPosition) 
VALUES(
'".$Name."',
'".$Surname."',
'".$FatherName."',
'".$Email."',
'".$Password."',
'".$Phone."',
'".$DegreeID."',
'".$RankID."',
'".$Organization."',
'".$Department."',
'".$Country."',
'".$City."',
'".$Address."',
'".$Job."'
);";
    //execute SQL-query
    $result = mysql_query($sql, $db);
    if (!$result) 
    {
        die('Invalid query: ' . mysql_error());
    }
    //close database  = very inportant
    mysql_close($db);

}
?>

phpMyAdmin中也有此类信息:

auto increment increment    1
auto increment offset   1
autocommit  ON
automatic sp privileges ON
back log    50
basedir \usr\local\mysql-5.1\
big tables  OFF
binlog cache size   32,768
binlog format   STATEMENT
bulk insert buffer size 8,388,608
character set client    utf8
(Global value)  cp1251
character set connection    utf8
(Global value)  cp1251
character set database  cp1251
character set filesystem    binary
character set results   utf8
(Global value)  cp1251
character set server    cp1251
character set system    utf8
character sets dir  \usr\local\mysql-5.1\share\charsets\
collation connection    utf8_general_ci
(Global value)  cp1251_general_ci
collation database  cp1251_general_ci
collation server    cp1251_general_ci
completion type 0
concurrent insert   1

因此,我需要正确地显示,保存并从数据库中选择俄语文本。谢谢!连接超时10 datadir \ usr \ local \ mysql-5.1 \ data
\


阅读 372

收藏
2020-05-17

共1个答案

小编典典

mysql_set_charset('utf8');连接到数据库后尝试调用。我认为这与执行SET NAMES查询相似,但是由于PHP手册指出建议在SET
NAMES查询上使用该功能,因此,我会尝试使用它。

另外,在显示内容时,您可以尝试 echo htmlentities($string, ENT_COMPAT, 'UTF-8');

2020-05-17