0

我有查询,我有数据库。当我在 dbforge(mysql) 中查询时,我得到了结果。当从 php 时,我什么都没有。不明白为什么?如果我编写简单的查询,例如“从 id = 1 的表中选择 *”,它就可以工作。在我的代码下面:

<?php
            $conn = mysqli_connect("localhost", "username", "pass", "db");
            ini_set('max_execution_time', 300);     
            if (mysqli_connect_errno()) 
            {
                printf("Connect failed: %s\n", mysqli_connect_error());
                exit();

            }
            mysqli_query($conn, "SET CHARACTER SET utf8 ");

            $result = mysqli_query($conn, "Select distinct level_two FROM reportls._report_sales_report Where level_one = 'Музыка'");
            if($result == false)
            {
                die('INVALID QUERY: '.mysqli_error($conn));
                echo "error";
            }               
            while ($data = mysqli_fetch_row($result)) 
            {
            if(!empty($data[0]))
              $sendBack = $sendBack."<option value=\"$data[0]\">$data[0]</option>";
            }
            echo ($sendBack);
            $sendBack = '';
            mysqli_free_result($result);
?>

此代码不返回任何内容。但是,如果我将查询粘贴到我的 dbforge 中,它会返回行。你能帮我,或者写一些热门歌曲吗?我写的不正确?

4

1 回答 1

0

当您将 charset 设置为utf8

/* change character set to utf8 */
if (!$mysqli->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
    printf("Current character set: %s\n", $mysqli->character_set_name());
}

有关。

于 2015-04-29T11:23:54.857 回答