php - 在 mysql 数据库中显示随机字符而不是 Unicode。?

标签 php mysql database unicode

我需要保存一些孟加拉语unicode的句子,比如

 আমি ভাত খাই ( english: I eat rice)

为此,我在 MySql 中创建了一个排序规则为“utf8_unicode_ci”的数据库。 现在,每当我插入一个新句子时,它都会在表格中显示一些随机字符。例如上面的行 phpmyadmin 显示,

 আমি ভাত খাই

我尝试了很多方法来解决这个问题,但没有任何效果。我还添加了

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

在头部。

但是,当我直接从 phpmyadmin 插入一个 unicode 句子,例如“আমি ভাত খাই”时>插入它有效。

请帮助。谢谢。

<<我的最小>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Thesis</title>
    <link rel="stylesheet" href="css/style.css" />
    </head>
    <body>  
        <div id="frame">
            <table  style="width:95%;margin:0 0 0 2%;  color: rgba(0,0,0,0.6);
text-shadow: 2px 8px 6px rgba(0,0,0,0.2),
                 0px -5px 35px rgba(255,255,255,0.3);"><tr><td  align="center"><font color="#000" face="Arial, Helvetica, sans-serif" style="font-size:18px; font-weight:bold;">&nbsp;Natural Language Processing - Sentence Store For N-Gram </font></td></tr></table> <br />
            <form action="" method="post" enctype="multipart/form-data">
                <table  style="width:100%; height:auto">
                    <tr>
                        <td align="center"><input type="text"   class="outer" style="width:90%; font-size:20px;height:25px; font-weight:bold;" name="data" required autofocus onkeydown = "if (event.keyCode == 13)
                        document.getElementById('btnSearch').click()"  ></td>
                    </tr>
                    <tr>
                        <td align="center"><input type="submit" name="submit" id = "btnSearch" value="Save" style="width:200px;height:40px; font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:18px; color:#0099FF"/></td>
                    </tr>
               </table>    
            </form>
        </div>
   </body>
</html>
<?php
  if(isset($_POST['submit'])){
        include('db.php');
            $data = trim($_POST['data']);
            $qry=mysql_query("INSERT INTO sentence_tab VALUES('','$data')");
            if($qry){
                echo "SUCCESS";
            }
            else
            {
                echo "FAILURE";
            }
    }       
?>

最佳答案

也许尝试设置您正在使用的字符集会有所帮助。据我所知,您在 mysql 中使用 utf8_unicode_ci 所做的设置只是如何将其保存在数据库中。现在您必须确保使用相同的字符集进行交付。

我会尝试类似的东西

mysql_set_charset("UTF8");

就在 mysql_query() 之前

http://php.net/manual/en/function.mysql-set-charset.php

关于php - 在 mysql 数据库中显示随机字符而不是 Unicode。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35624627/

相关文章:

database - 在 Access 中的天数后用 'nd' 或 'th' 格式化日期

PHP Order By 不起作用

php - MySQL PHP 查询无效 - 找不到列

php - 从三重内连接获得正确的结果

mysql - 从表中删除具有唯一 ID 的行

python - Django - 在保存方法中执行查询

mysql - 使用 WP_Query 编写查询

database - Neo4j 密码 : Find common nodes between a set of matched nodes

php - 来自 Facebook Messenger 机器人的空消息

ios - 架构 i386 : "_sqlite3_open", 的 undefined symbol 引用自:错误