我有查询,我有数据库。当我在dbforge(mysql)中查询时,我得到了结果。从php开始,我什么都没得到。无法理解为什么?如果我写的查询简单如“select * from table where 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中,它将返回行。 你能帮助我,还是写一些点击?我写的不正确?
答案 0 :(得分: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());
}
与this相关。