0

I have a php file which has to authenticate user login data against a database of a forum software. I have problems selecting the right row of the members table for usernames which use German special chars like ä, ö, ü - It can't find the according row. However if I do the same query with MySQL workbench I can find the according member. Thus I think there is a problem with the PDO connection or my php file.

PHP Part to select the member row:

/* Get all Member attributes for the username */
$query = $db->prepare("SELECT * FROM members WHERE members_l_username = :name");
$query->bindValue(':name', $username);
$query->execute();
$member = $query->fetch(PDO::FETCH_ASSOC);

Creation of the PDO Object:

try {
    $db = new PDO("mysql:host=$dbhost;port=3306;dbname=$dbname;charset=utf8", $user, $pass);
}catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}

Settings of the table column: enter image description here

Why I can't find the row for $username="Mark Fröst" even though it exists (and the query works with MySQL workbench)?

kentor
  • 16,553
  • 20
  • 86
  • 144
  • have you tried printing the value of $username using charset utf-8 on your browser? It may not be encoded correctly in the variable. – Paul Carlton Oct 27 '15 at 18:10
  • The value is coming from an application, thus I can't echo it. Anyways I have saved the passed $username into a logfile and the value was fine once I set the logfile encoding to UTF8 (I did this using Notepad++). – kentor Oct 27 '15 at 18:15
  • Try changing PDO connector to `charset=utf8mb4` instead of `charset=utf8`. I'd look at this thread for additional steps/issues, http://stackoverflow.com/questions/279170/utf-8-all-the-way-through. – chris85 Oct 27 '15 at 18:32
  • @chris85 this hasn't helped either unfortunately. – kentor Oct 27 '15 at 18:49
  • You cant echo `$username` before `$query = $db->prepare("SELECT * FROM members WHERE members_l_username = :name");`? – chris85 Oct 27 '15 at 20:24
  • Basically I can, but not that easy as you think. However to make it short: The $username is being showed correctly there – kentor Oct 27 '15 at 22:21

0 Answers0