如何从MySQL数据库中取“印地语”हिन्दीtext(印度当地语言)

时间:2016-06-09 03:21:52

标签: php mysql

存储我的数据的数据库是:

enter image description here

现在我想获取该数据并在我的php页面上显示,但是当我尝试在我的php代码中获取数据时,我将文本输入以下格式

UID= ????/??????????/????/?????/?????/Test upgrade/1
UID= ????/??????????/??????/??????/??????????/159/1
UID= ????/??????????/??????/??????/??????????/190/1
UID= ????/??????????/??????/??????/??????????/194/1
UID= ????/??????????/??????/???????/?????? (??.)/730/1
UID= ????/??????????/??????/???????/?????? (??.)/742/1/1
UID= ????/??????????/??????/???????/?????? (??.)/732/1
UID= ????/??????????/??????/??????/??????/98/8/1
UID= ????/??????????/??????/??????/??????/48/10/1

参考这个问题,我已将我的数据库字符集更改为" utf8_unicode_ci",但仍无效。我写了以下代码来获取数据

数据库连接页

<?php
    // Database configuration
    $dbHost = "localhost";
    $dbUsername = "user";
    $dbPassword = "xxxxxxxxxxxxx";
    $dbName = "tutorialsssxxxxx";

    // Create database connection
    $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

    // Check connection
    if ($db->connect_error) {
        die("Connection failed: " . $db->connect_error);
    }
?>

和索引页

<?php
include $_SERVER['DOCUMENT_ROOT']."/header.php";
?><br>

<!DOCTYPE HTML>
<html lang="hi">
<head>
<title><?php echo $_GET['dta']; ?> Tutorials  Mrtutorials.net</title>
<link href='style.css' rel='stylesheet' type='text/css'>
<script src="jquery.min.js"></script>
<script type="text/javascript">
// Show loading overlay when ajax request starts
$( document ).ajaxStart(function() {
    $('.loading-overlay').show();
});
// Hide loading overlay when ajax request completes
$( document ).ajaxStop(function() {
    $('.loading-overlay').hide();
});
</script>


</head>
<body>      
<div class="content">
    <div class="dta"> <div class="list_item"><h2><?php echo $_GET['dta']; ?> Tutorials</h2></div>
<div class="post-wrapper">
    <div class="loading-overlay"><div class="overlay-content">Loading.....</div></div>
    <div id="posts_content">
    <?php
    //Include pagination class file
    include('Pagination.php');

    //Include database configuration file
    include('dbConfig.php');

    $limit = 10;

    //get number of rows
    $queryNum = $db->query("SELECT COUNT(*) as postNum FROM posts");
    $resultNum = $queryNum->fetch_assoc();
    $rowCount = $resultNum['postNum'];

    //initialize pagination class
    $pagConfig = array('baseURL'=>'getData.php', 'totalRows'=>$rowCount, 'perPage'=>$limit, 'contentDiv'=>'posts_content');
    $pagination =  new Pagination($pagConfig);

    //get rows
    $query = $db->query("SELECT * FROM posts Where type=$yyy ORDER BY id DESC LIMIT $limit");

    if($query->num_rows > 0){ ?>
        <div class="posts_list">
        <?php
            while($row = $query->fetch_assoc()){ 
                $postID = $row['id'];
        ?>

<table width="" border="0" cellspacing="5" cellpadding="0">
   <tr class="up"> 
     <td style="font-size: 45px; padding-left:5px; padding-right:5px"><?php echo $row["id"]; ?></td>
     <td valign="left" width="100%"><a href="/Ask/<?php echo $row["id"]; ?>/<?php echo $row["folder"]; ?>"><?php echo $row["title"]; ?></a> <br>  <?=$value['type']?></td>
   </tr>
 </table>

        <?php } ?>
        </div>
        <?php echo $pagination->createLinks(); ?>
    <?php } ?>
    </div>
</div></div>
</div>

</body>
</html><?php
include $_SERVER['DOCUMENT_ROOT']."/footer.php";
?>

4 个答案:

答案 0 :(得分:5)

您需要使用&#34; set_charset&#34;

试试这个:(在你的index.php中)

//initialize pagination class
    $pagConfig = array('baseURL'=>'getData.php', 'totalRows'=>$rowCount, 'perPage'=>$limit, 'contentDiv'=>'posts_content');
    $pagination =  new Pagination($pagConfig);

    mysqli_set_charset( $db, 'utf8');

    //get rows
    $query = $db->query("SELECT * FROM posts Where type=$yyy ORDER BY id DESC LIMIT $limit");

准确地说,在您的情况下,您需要在获取db的代码中添加它:

mysqli_set_charset( $db, 'utf8');

答案 1 :(得分:1)

=将帮助您在数据库连接上设置mysqli_set_charset( $db, 'utf8');。现在要在页面中显示它,你仍然需要在html中设置字符编码。

请记住这样做。否则,您的页面仍然不会显示unicode字符。

unicode

答案 2 :(得分:0)

在stackoverflow.com上,按照我的回答,对我来说没有任何作用,无法显示在网页上,即通过PHP通过MySql编写的北印度语文本。

以下代码对我有用。请写下您的评论

enter code here

$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM audio  WHERE AudioFor= 'Aarti' ORDER BY Name";
mysqli_set_charset( $conn, 'utf8');  **//  to get the hindi font/text displayed**
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) { ?>



    <table cellpadding="10">
<thead>
<tr align= "centre"><h3> Other Aartis  </h3></tr>
            <tr>

                 <th>Aarti Of</th>
                 <th>Wordings</th>                
                <th>Click to Listen</th>
                </tr>

<?php
    while($row = mysqli_fetch_assoc($result)) {
        echo "<tr><td >" . $row["Name"]."</td><td >" . $row["Wording"]. "</td><td >". ' <a href="' . $row["AudioPath"].'">Click To Listen </a>'. '</td></tr>';
    }
} //else {
   // echo "0 results";
//}
?>

答案 3 :(得分:0)

连接到SQL Server和数据库后,运行以下查询

msql_query("SET CHARACTER SET utf8")