phphtmlmysqlencodingcyrillic

Cyrillic str encoded in Mysql inside PHP script


I have the string "тест123" in Cyrillic and am executing a MySQL query with it inside a PHP script.

However, the string in the query gets encoded and instead of "test123", it becomes "%d1%82%d0%b5%d1%81%d1%82+123". So the result is not a working query, which looks like this:

SELECT text, MATCH(text) AGAINST ('%d1%82%d0%b5%d1%81%d1%82+123'  IN NATURAL LANGUAGE MODE) AS score FROM temp_text

The expected result should be

SELECT text, MATCH(text) AGAINST ('тест123'  IN NATURAL LANGUAGE MODE) AS score FROM temp_text

I have my connection encoded like this

mysqli_set_charset($connect, 'utf8mb4');

Solution

  • This is not a MySQL problem, but a HTML / PHP problem.

    %d1%82%d0%b5%d1%81%d1%82+123
    

    is the "urlencoding" of the Cyrillic

    тест123
    
    Your PHP code should apply urldecode to it before handing to MySQL.
    
    Or... Possibly the string had been sent through urlencode() twice before arriving.