Skip to content
Advertisement

PHP/SQL – Searching a DB in a different language

I have a simple product search on my site like so:

$params = [$term];
$sql = "SELECT * FROM products WHERE MATCH(product_name) AGAINST(?)";
$stmt = DB::run($sql,$params);
$resultCount = $stmt->rowCount();
if($resultCount > 0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        //get search results
    }
}

My site is all in English and my DB is all in English, but according to my analytics we had someone from Portugal search in Portuguese on the Site but they didn’t get any results even though there was results there for the translated version of what they searched for.

Is there anyway to get around this or detect the language they are inputting and translate it without having to pay for Google Translate or similar.

Advertisement

Answer

I suppose he was searched with portuguese like this: óà

You can:

  1. Add translations of your content and search in them
  2. Convert non-English letters to English and then search.
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement