What potential encoding issues can arise when storing hashed passwords in a MySQL database using PHP?

When storing hashed passwords in a MySQL database using PHP, potential encoding issues can arise if the database or table is not set to use the correct character set and collation. To ensure proper encoding, it is important to set the character set and collation of the database and table to UTF-8. This will prevent any encoding mismatches that could occur when hashing or verifying passwords.

// Set the character set and collation for the database connection
$mysqli = new mysqli("localhost", "username", "password", "database");
$mysqli->set_charset("utf8");

// Set the character set and collation for the specific table
$mysqli->query("SET NAMES 'utf8'");

// Now you can safely store hashed passwords in the MySQL database