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 ü
.