What are the potential pitfalls of querying a database for multilingual content in PHP?

When querying a database for multilingual content in PHP, one potential pitfall is not properly handling character encoding. This can lead to issues with special characters or non-ASCII characters not displaying correctly. To solve this, make sure to set the correct character encoding for your database connection and properly sanitize and escape user input to prevent SQL injection attacks.

// Set character encoding for database connection
mysqli_set_charset($conn, "utf8");

// Sanitize and escape user input before using in query
$userInput = mysqli_real_escape_string($conn, $_POST['user_input']);

// Query database for multilingual content
$query = "SELECT * FROM multilingual_table WHERE content LIKE '%$userInput%'";
$result = mysqli_query($conn, $query);

// Process query results
while ($row = mysqli_fetch_assoc($result)) {
    // Display multilingual content
    echo $row['content'];
}