1

I have a Thai language content in m MySQL Database with collation utf8_unicode_ci

i have used the following to display it correctly on my webpage

<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>

my DB connection file has following code

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

Now the PROBLEM is it displays correctly, BUT my SEARCH BOX can not search it if somebody tries searching in Thai language, but searches correctly with english content present in the database

following is my code for SEARCH

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

1 Answers1

0

The function utf8_decode does not support the conversion of Thai characters, as the format in PHP it converts to is ISO-8859-1, a character set that is ASCII like (thus not supporting Thai characters).

This means that the Thai characters will be replaced by "?" and so no results will be found, unless you have entries with question marks.

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

Where did the Boolean error occur? This will help the community find a solution to your problem.

Using:

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

will enable PHP run time errors

EDIT: Try this code to get any mysqli errors:

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 https://stackoverflow.com/a/22582272/5287820

wpgbrown
  • 40
  • 9
  • Instead of this $search1=$_GET['search']; $search=utf8_decode($search1); if i use just $search=$_GET['search']; it throws boolean error – Kedar Patwa Oct 01 '17 at 17:38
  • Do you know where in the code the boolean error is thrown? – wpgbrown Oct 01 '17 at 17:43
  • You can find this by enabling errors using error_reporting(E_ALL); ini_set('display_errors', 1); – wpgbrown Oct 01 '17 at 17:43
  • when i dont have the decode function in use, and if I search by any thai characters instead of english Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/../index.php on line 365 line 365 is $num=mysqli_num_rows($result); if($num > 0) { – Kedar Patwa Oct 01 '17 at 17:55
  • Try adding in the script above: It tells you mysqli errors, and the Boolean is telling your of this error. – wpgbrown Oct 01 '17 at 18:13
  • error part did get solved but the real problem about the language is still troubling me, the above answer does explains the problem in an accurate way but what is the solution to it, i am sure there is a way out because i see several thai websites working correctly – Kedar Patwa Oct 05 '17 at 18:20
  • Make sure that the Thai characters in the database are being stored correctly. If you don't change the column character set to UTF8, then the characters won't be stored correctly. Try outputting the result of your query. It may give you some clues about what is happening – wpgbrown Oct 06 '17 at 20:34