需要注意的事项: 1. 确保您的 html 或 php 文件可以呈现内容:i)<?php header('Content-Type: text/html; charset=utf-8'); ?>
或 ii)。
<?php $page_html = "<html>";
$page_html .= "<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=utf-8\">";
$page_html .= "<body>";
$page_html .= " process and display your content from the database here ";
$page_html .= "</body></html>";
echo $page_html;
- 确保您有正确的排序规则,如下所述。( :) 一切顺利 )
因此,就我而言,我尝试将排序规则从utf8mb4_unicode_ci
for mysql 更改为uft8_general_ci
.
然后粘贴:
mysqli_set_charset( $con, 'utf8');
就在我执行 SELECT 命令之前。
这是我从 db 读取的代码:
/*
$DB_SERVER="db_server_name";
$DB_USER_READER="root";
$DB_PASS_READER="passw*rd";
$DB_NAME="db_name";
$DB_PORT="port number";
$SELECT_WHAT="`name_of_column_as_in_your_table`";
$WHICH_TBL="`table_name`";
$ON_WHAT_CONDITION="`id`='7'";
*/
$con = mysqli_connect($DB_SERVER, $DB_USER_READER, $DB_PASS_READER, $DB_NAME, $DB_PORT);//this is the unique connection for the selection
mysqli_set_charset( $con, 'utf8');
$slct_stmnt = "SELECT ".$SELECT_WHAT." FROM ".$WHICH_TBL." WHERE ".$ON_WHAT_CONDITION;
$slct_query = mysqli_query($con, $slct_stmnt);
if ($slct_query==true) {
//Do your stuff here . . .
}
它就像一个魅力。一切顺利。上面的代码可以从数据库的表列中读取中文、俄文或阿拉伯文或任何国际语言,其中包含此类数据。