get_results query with accent

Question

I’m trying to do an sql query and I don’t understand something
I get a value with $ _POST, this value is equal to ‘définition’.
I made this request:
$sql = "SELECT DISTINCT * FROM". $ wpdb-> prefix. "posts WHERE post_title LIKE '%". $ _POST ['value']. "% '";

A var_dump($sql) gives "SELECT DISTINCT * FROM datatablename.posts WHERE post_title LIKE '% definition%'";

If I do
$res = $wpdb->get_results($sql);
I get an empty array

but, if in my code I put directly
$sql = "SELECT DISTINCT * FROM datatablename.posts WHERE post_title LIKE '% definition%'";
(I immediately replace $ _POST with my value),
$res is an array with a post

The problem stems from the accent, because if $_POST['value'] = 'finition' it’s okay

My datatable is in utf8mb4_unicode_ci

What can be done to solve this problem ?

0
user7734861 2 years 2020-10-24T12:10:22-05:00 0 Answers 15 views 0

Leave an answer

Browse
Browse