0

I am using a pdo connection to my mysql database (utf8_general_ci) and the connection sets charset to charset=utf8:

public function connect() {
    $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbName . ';charset=utf8';
    $pdo = new PDO($dsn, $this->user, $this->pwd);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    return $pdo;
    }
}

I got an input fields where users can search for author, title and year:

<input class="search-input" name="search" type="text">

My php query looks like this:

   $sql = "SELECT * FROM db WHERE author LIKE ? AND title LIKE ? AND year LIKE ?";
    $stmt = $this->connect()->prepare($sql);
    $stmt->execute([$author_query, $title_query, $date_query]);
    $result = $stmt->fetchAll();

The query works fine except that the search query isn't 'special character sensitive'. If the user searches for "mü" (German) or "då" (Danish?), the query will also spit out data that contains "mu" or "da", basically ignoring ü and å and defaulting it to the base characters. Ideal would be if I only get results that contain ü if the user enters ü.

Dharman
  • 30,962
  • 25
  • 85
  • 135
sojutyp
  • 316
  • 1
  • 2
  • 11
  • 3
    Go look into _collations_. https://dev.mysql.com/doc/refman/8.0/en/charset.html – CBroe Nov 01 '21 at 12:05
  • 1
    Think you need a different collation, https://dba.stackexchange.com/questions/122607/which-accented-characters-are-considered-the-same – user3783243 Nov 01 '21 at 12:06
  • 1
    show us the create table of your table and see if you have the a collation with support that – nbk Nov 01 '21 at 12:07

0 Answers0