What role does collation play in PHP databases, and what is the recommended collation for case sensitivity?

Collation in PHP databases determines how string comparison operations are performed, including whether they are case-sensitive or case-insensitive. The recommended collation for case sensitivity is usually "utf8_bin" or "utf8mb4_bin" as they treat characters with different cases as distinct.

// Setting collation for a MySQL database connection in PHP
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Set collation for the connection
$conn->set_charset("utf8mb4");
$conn->query("SET collation_connection = 'utf8mb4_bin'");