Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我看到的不是俄语数据,而是英语数据_Php_Mysql_Sql_Mysqli - Fatal编程技术网

Php 我看到的不是俄语数据,而是英语数据

Php 我看到的不是俄语数据,而是英语数据,php,mysql,sql,mysqli,Php,Mysql,Sql,Mysqli,我有俄语网站,我看到的不是俄语数据,而是英语数据 <?php $dbc_utf8 = mysqli_connect ("mysite.com", "xxxxxxxxxxx", "xxxxxxxxxxx", "xxxxxxxxxxx"); mysqli_query($dbc_utf8, 'SET CHARACTER utf8'); mysqli_query($dbc_utf8, 'SET NAMES utf8'); /* Inst

我有俄语网站,我看到的不是俄语数据,而是英语数据

   <?php 
    $dbc_utf8 = mysqli_connect ("mysite.com", "xxxxxxxxxxx", "xxxxxxxxxxx", "xxxxxxxxxxx");
    mysqli_query($dbc_utf8, 'SET CHARACTER utf8');
    mysqli_query($dbc_utf8, 'SET NAMES utf8'); 
             /*  Installing Russian locale Connection */
             mysqli_query($dbc_utf8, "SET lc_time_names = 'ru_RU'") ;    
    ?>
在数据库中

$sql = "
        SELECT id, parent_id, name, comment,
        DATE_FORMAT(date_add, '%d %M %Y') as date_add
        FROM comment_common
";

从数据库中获取时间,并将其放在变量上。然后尝试以下代码:

如果您在服务器上运行Linux,请使用:

setlocale(LC_ALL, 'ru_RU.UTF-8');
echo strftime(); //PS down
您可以从中学习如何使用此功能

如果您使用的是Windows:

<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
setlocale(LC_ALL, 'russian');

setlocale(LC_ALL,“俄语”);

您应该运行这些查询,将它们放在一个SQL运行中

$sql = "
SET lc_time_names = 'ru_RU'; 
SELECT id, parent_id, name, comment,
        DATE_FORMAT(date_add, '%d %M %Y') as date_add
        FROM comment_common;";
如果我在phpMyAdmin中以这种方式运行它,我就用正确的语言显示了它:
14ССбббб2014
,但当我第一次运行第一个查询,然后第二个查询时,我也有英语数据

   <?php 
    $dbc_utf8 = mysqli_connect ("mysite.com", "xxxxxxxxxxx", "xxxxxxxxxxx", "xxxxxxxxxxx");
    mysqli_query($dbc_utf8, 'SET CHARACTER utf8');
    mysqli_query($dbc_utf8, 'SET NAMES utf8'); 
             /*  Installing Russian locale Connection */
             mysqli_query($dbc_utf8, "SET lc_time_names = 'ru_RU'") ;    
    ?>
要获得所需的结果,您应该使用
mysqli\u store\u result()
函数,因此正确的代码是:

<?php

header('Content-Type: text/html; charset=utf-8');
$dbc_utf8 = mysqli_connect ("localhost", "root", "", "tests");
mysqli_query($dbc_utf8, 'SET CHARACTER utf8');
mysqli_query($dbc_utf8, 'SET NAMES utf8');
/*  Installing Russian locale Connection */
$sql = "
SET lc_time_names = 'ru_RU';
 SELECT id, parent_id, name, comment,
        DATE_FORMAT(date_add, '%d %M %Y') as date_add
        FROM comment_common
";

if (mysqli_multi_query($dbc_utf8, $sql)) {
    do {
        /* store first result set */
        if ($result = mysqli_store_result($dbc_utf8)) {
            while ($row = mysqli_fetch_assoc($result)) {
                echo $row['date_add'];
            }
            mysqli_free_result($result);
        }

    } while (mysqli_more_results($dbc_utf8) && mysqli_next_result($dbc_utf8));
}
?>

然而,在这种情况下,您需要管理员权限,我不知道为什么,但这段代码在第一次运行时不起作用,从第二次运行开始,它以俄语返回日期。

您使用的是什么版本的mysql?您的服务器操作系统是什么?在这种情况下,我有“错误查询数据库”。我使用
<?php

header('Content-Type: text/html; charset=utf-8');
$dbc_utf8 = mysqli_connect ("localhost", "root", "", "tests");
mysqli_query($dbc_utf8, 'SET CHARACTER utf8');
mysqli_query($dbc_utf8, 'SET NAMES utf8');
/*  Installing Russian locale Connection */
mysqli_query($dbc_utf8, "SET GLOBAL lc_time_names = 'ru_RU'") ;

$sql = "
        SELECT id, parent_id, name, comment,
        DATE_FORMAT(date_add, '%d %M %Y') as date_add
        FROM comment_common
";

$result = mysqli_query($dbc_utf8, $sql);

$row = mysqli_fetch_assoc($result);

echo $row['date_add'];



?>