SELECT statement does not work with utf-8

I have a select statement that should select all the data in the database equal to Arabic input, I have exactly set the database mapping to utf8_general_ci and the table column. And in the file

$conn = mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_database); 
mysqli_query($conn, "set names 'utf8'");
mysqli_query($conn, "SET character_set_results=utf8");
mb_http_output('UTF-8'); 
mb_internal_encoding('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
mb_language('uni'); 
mb_internal_encoding('UTF-8');
mysqli_set_charset($conn, "utf8");

And the search code

$question = $_REQUEST['question'];
$table = $_REQUEST['subject'];
if(empty($question)) {
echo "Type a question!"; }
$qe = mysqli_escape_string($conn, $question);
$full = "SELECT * FROM $table WHERE question LIKE '%$qe%'";
$fullQ = mysqli_query($conn, $full);
if(!$fullQ) {
echo mysqli_error($conn);
}
echo "<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>";
printf(nl2br("\n%u\n"), mysqli_num_rows($fullQ));
while($row = mysqli_fetch_assoc($fullQ)) {
printf(nl2br("\n%s\n"), $row['question']);
}

It works if I print all the data without using WHERE, and also prints the SQL syntax after it is sent from the first page to the second from the right with the correct Arabic characters. But it always returns 0 rows.

+4
source share
1 answer

If your database is saved in Arabic, then configure the connection string to the following

$con1 = mysqli_connect($HOSTURL,$DBUSER,$DBPASSWORD,$DBNAME);

    // Check connection
        if (mysqli_connect_errno())
          {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
            die('');
          }
        mysqli_query($con1,"SET NAMES utf8");   
      //else{echo "Connection Done";}

If your database is not encoded, you do not need to specify utf8 in your connection string.

0
source

Source: https://habr.com/ru/post/1612148/


All Articles