dpdbu24262
2016-06-09 03:21
浏览 152
已采纳

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

Database which stores my data is this:

enter image description here

Now I want to fetch that data and display on my php page, but when I'm trying to fetch data in my php code I'm getting text into the following formate

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

Referring to this question I have changed my database charset to "utf8_unicode_ci", but Still not working. I have written following code to fetch the data

datebase connection page

<?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);
    }
?>

and index page

<?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条回答 默认 最新

  • duanluan8390 2016-06-09 03:43
    最佳回答

    You need to use "set_charset"

    Try this: (in your 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");
    

    To be precise, In your case you need to add this in code where you fetching the db:

    mysqli_set_charset( $db, 'utf8');
    
    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题