I have a problem with a MySQL query in PHP when I'm having non English language, it is always returning 0 rows. The query is pretty straight forward and here is the relevant snippet.
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT ID, post_content FROM udhay.posts WHERE post_content = 'இ'";
$query = $conn->query($sql);
if ($query->num_rows > 0) {
// output data of each row
while ($row = $query->fetch_assoc()) {
print_R($row);die;
}
} else {
echo "0 results \n\n";
}
The only odd thing you could find here is the WHERE condition is having a Tamil character.
I checked even the MySQL error log and found that the right query got executed and tried that query once again directly in the MySQL and it is working perfectly. Also I tried with some English letters and words and it is completely working fine without any issues.
Version Info:
MySQL:
mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using EditLine wrapper
PHP:
PHP 5.6.28 (cli) (built: Dec 22 2016 01:56:27)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
Any clue on this or solution would really be great.