Php 搜索输入GET/POST数据无法理解来自MySQL DB的utf8_unicode_ci泰语数据
我在MySQL数据库中有一个泰语内容,排序规则为utf8\u unicode\u ci 我已使用以下方法在我的网页上正确显示它Php 搜索输入GET/POST数据无法理解来自MySQL DB的utf8_unicode_ci泰语数据,php,search,utf-8,thai,Php,Search,Utf 8,Thai,我在MySQL数据库中有一个泰语内容,排序规则为utf8\u unicode\u 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; <
<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>
现在的问题是它显示正确,但如果有人尝试用泰语搜索,我的搜索框无法搜索它,而是使用数据库中的英语内容正确搜索
以下是我的搜索代码
<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;
}
?>
函数utf8_decode不支持泰语字符的转换,因为它转换为的PHP格式是ISO-8859-1,一种类似ASCII的字符集(因此不支持泰语字符)
这意味着泰语字符将被替换为“”,因此不会找到结果,除非您有带问号的条目
参考:
布尔错误发生在哪里?这将帮助社区找到解决您问题的方法
使用:
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();
}
在中,utf8_decode函数不支持泰语字符的转换,因为它转换为的PHP格式是ISO-8859-1,一种类似ASCII的字符集(因此不支持泰语字符) 这意味着泰语字符将被替换为“”,因此不会找到结果,除非您有带问号的条目 参考: 布尔错误发生在哪里?这将帮助社区找到解决您问题的方法 使用:
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();
}
from而不是$search1=$\u GET['search']$搜索=utf8_解码($search1);如果我只使用$search=$\u GET['search'];它抛出布尔错误您知道布尔错误在代码中的何处抛出吗?您可以通过使用错误报告(E_ALL)启用错误来找到这一点;ini设置(“显示错误”,1);当我没有使用decode函数时,如果我用任何泰语字符而不是英语搜索,警告:mysqli_num_rows()期望参数1为mysqli_result,第365行/home/./index.php中给出的布尔值为$num=mysqli_num_rows($result);如果($num>0){尝试在上面的脚本中添加:它告诉你mysqli错误,布尔值告诉你这个错误。而不是这个$search1=$\u GET['search'];$search=utf8\u decode($search1);如果我只使用$search=$\u GET['search'];它抛出布尔错误您知道布尔错误在代码中的何处抛出吗?您可以通过启用错误报告(E_ALL);ini_set('display_errors',1);当我没有使用解码功能时,以及如果我搜索任何泰文字符而不是英文警告:mysqli_num_rows()预期参数1为mysqli_result,第365行/home/./index.php中给出的布尔值为$num=mysqli_num_rows($result);如果($num>0){尝试在上面的脚本中添加:它告诉您mysqli错误,布尔值告诉您此错误。