2016-02-25 63 views
1

我需要一些句子這是在孟加拉語unicode.Such保存爲在mysql數據庫中顯示隨機字符而不是Unicode。

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

出於這個目的,我創造了在MySQL整理「utf8_unicode_ci」的數據庫。 現在,每當我插入一個新句子的表格它顯示了一些隨機characters.Such作爲上述線路的phpmyadmin顯示,

আমি ভাত খাই 

我試圖以多種方式解決這個問題,但沒有worked.I還增加

<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"; 
      } 
    }  
?> 
+0

從'mysql_ *'界面改爲'mysqli_ *'。 –

回答

1

也許試圖設置您所使用的字符集幫助。據我所知,您在mysql中使用utf8_unicode_ci所做的設置就是如何將其保存在數據庫中。現在你必須確保你使用相同的字符集。

我會嘗試像

mysql_set_charset("UTF8"); 

請求mysql_query()

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

+0

謝謝....它完美的作品。 –

0
  1. 確保您的字符集數據庫,表的前右列是 「utf8_general_ci」 。

  2. 你的MySQL連接代碼之後把這個代碼

mysql_query("SET NAMES 'utf8'", $db_con); OR mysql_set_charset('utf8', $db_con);

這應該可以解決您的問題。