Przepisując klasę do obsługi użytkownika z MySQLi na PDO natrafiłem na dziwny problem.

Kiedy chcę się zalogować z nazwą użytkownika zaczynającą się od małej litery, logowanie nie działa. Jest włączone rozpoznawanie wielkości znaków.
Kodowanie w bazie ustawione jest na utf8_general_ci ,więc wielkość znaków nie powinna być brana pod uwagę, a jednak jest.

Przy MySQLi nie ma tego problemu. Loguje się bez rozpoznawania wielkości znaków.
Próbowałem innych kodowań m.in utf8_bin , ale też nic nie pomaga. Problem występuje tylko przy korzystaniu z PDO.

Co może być tego przyczyną?

  1. private $config = array(
  2. 'dsn' => 'mysql:host=localhost;dbname=various' ,
  3. 'user' => 'root' ,
  4. 'password' => ''
  5. );
  6.  
  7. public function __construct()
  8. {
  9. try
  10. {
  11. $this->db = new PDO($this->config['dsn'], $this->config['user']
  12. , $this->config['password']);
  13. }
  14. catch (Exception $error)
  15. {
  16. echo 'Message: '.$error->getMessage();
  17. }
  18. }
  19.  
  20. public function login($username,$password)
  21. {
  22. $stmt = $this->db->prepare('SELECT id,username,password,email,salt,role FROM users
  23. WHERE username=:username');
  24. $stmt->bindValue(':username', $username);
  25. $stmt->execute();
  26.  
  27. while ($row = $stmt-> fetch())
  28. {
  29. $this->user_id = $row['id'];
  30. $this->username = $row['username'];
  31. $this->password = $row['password'];
  32. $this->email = $row['email'];
  33. $this->salt = $row['salt'];
  34. $this->role = $row['role'];
  35. }
  36.  
  37. $stmt->closeCursor();
  38.  
  39. if ($username == $this->username AND $this->compare($password, $this->password, $this->salt))
  40. {
  41. $_SESSION['user_id'] = $this->user_id;
  42. $_SESSION['auth'] = TRUE;
  43. $_SESSION['username'] = $this->username;
  44. $_SESSION['role'] = $this->role;
  45.  
  46. return true;
  47. }
  48.  
  49. return false;
  50. }