I have a simple search using PHP and MySQL
it works perfectly for English text, but for Arabic text it will not retrieve any data without any Error
while executing the same MySQL query on Database "PhpMyAdmin" works perfectly
Result.PHP
<?php
if(!isset($_POST["search"])){$_POST["search"]="";}
echo $search=$_POST["search"];
$servername = "localhost";
$username = "aramtryf_laravel";
$password = "Reha@2015";
$dbname = "aramtryf_laravel";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sSQL= 'SET CHARACTER SET utf8';
mysqli_query($conn,$sSQL);
$sql = " SELECT * FROM oldorgs WHERE org_name like '%$search%' ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>
<th scope='row'>".$row["org_name"]."</th>
<td>".$row["gov"]."</td>
<td>".$row["sector"]."</td>
<td>".$row["email"]."</td>
</tr>";
}
}
$conn->close();
?>
instead of
$sSQL= 'SET CHARACTER SET utf8';
mysqli_query($conn,$sSQL);
try
mysqli_set_charset($conn,"utf8");
It's definitely works : Your html page set to meta data UTF-8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
OR In Mysql try this
$connect = mysql_connect("localhost","root","");
mysql_select_db("arabicd", $connect);
mysql_query("SET NAMES utf8");
Try adding
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
after the you connect to mysql.
or you can use this one.
mysqli_set_charset($conn, "utf8");
Mysql has a partial implementation of UTF-8. So I'd suggest you stick to the HTML UTF-8 for example:
<meta charset="utf-8">
Or you can use utf8mb4 to fully support UTF-8 in mysql.