1

我在 m MySQL 数据库中有一个泰语内容,带有排序规则 utf8_unicode_ci

我已使用以下内容在我的网页上正确显示

<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />
<style type="text/css">
.thai {
font-family:Tahoma, Arial Unicode MS;
font-size: 2em;
</style>
</head>
<body>
<div id="content"><span class="thai"><?php echo $row['description2'];?></span></div>

我的数据库连接文件有以下代码

mysqli_query($connection, "SET NAMES UTF8");

现在的问题是它显示正确,但是如果有人尝试用泰语搜索,我的搜索框无法搜索它,但是使用数据库中存在的英文内容正确搜索

以下是我的搜索代码

<form method="GET" action="index.php" accept-charset="UTF-8">
<input class="thai" type="text" charset="UTF-8" class="keyword" value="Search" name="search" id="q" onFocus="if(this.value==this.defaultValue) this.value='';" onBlur="if(this.value=='') this.value=this.defaultValue;" /><br />

</form>

<?php
require_once('inc/connect.php');

//NOT SURE IF THE FOLLOWING DECODING IS MAKING ANY SENSE, I still Get the -No result found- for thai language, but it made the boolean error go away

$search1=$_GET['search'];
$search=utf8_decode($search1);

$select1="SELECT * FROM products where id like '%$search%' || title like '%$search%' || size like '%$search%' ||description1 like '%$search%'|| description2 like '%$search%' order by id asc";



 $result=mysqli_query($connection, $select1);
    $num=mysqli_num_rows($result);
 if($num > 0)
 {
  while($row=mysqli_fetch_array($result))

  {
    $oid=$row['id'];

 echo $row['title'];




  }
  }
else{
  $ertx="No Records Found In Database";
 echo $ertx;
 }
?>
4

1 回答 1

0

函数 utf8_decode 不支持泰语字符的转换,因为它转换为的 PHP 格式是 ISO-8859-1,一个类似于 ASCII 的字符集(因此不支持泰语字符)。

这意味着泰语字符将被替换为“?” 所以不会找到任何结果,除非你有带问号的条目。

参考: http: //php.net/manual/en/function.utf8-decode.php

布尔错误发生在哪里?这将帮助社区找到解决您问题的方法。

使用:

error_reporting(E_ALL);
ini_set('display_errors', 1);

将启用 PHP 运行时错误

编辑:尝试此代码以获取任何 mysqli 错误:

if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    //you need to exit the script, if there is an error
    exit();
}

来自https://stackoverflow.com/a/22582272/5287820

于 2017-10-01T17:29:29.150 回答