更新时间:2023-01-31 09:01:04
需要注意的事项:
1.确保您的html或php文件将呈现内容,其中包含:
i)<?php header('Content-Type: text/html; charset=utf-8'); ?>
或者
ii).
Things to watchout for :
1. make sure with your html or php file that would render the content, has either :
i) <?php header('Content-Type: text/html; charset=utf-8'); ?>
OR
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
更改为mysql,并且不得不将其更改为uft8_general_ci
.
So in my case, I had tried changing the collation from utf8mb4_unicode_ci
for mysql and had to change it to uft8_general_ci
.
然后粘贴:
mysqli_set_charset( $con, 'utf8');
在执行SELECT命令之前.
right before I did the SELECT command.
这是我从db中读取的代码:
This is my code for reading from 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 . . .
}
它就像一种魅力.一切顺利.上面的代码可以从包含此类数据的数据库表列中读取中文,俄文或阿拉伯文或任何国际语言.
And it worked like a charm. All the best. The above code can work with reading chineese, russian or arabic or any international language from the database's table column holding such data.