In PHP MySQL queries, why is it recommended to use CHAR_LENGTH() instead of LENGTH() when working with strings to ensure accurate character count?

When working with strings in PHP MySQL queries, it is recommended to use CHAR_LENGTH() instead of LENGTH() to ensure an accurate character count. This is because LENGTH() returns the number of bytes in a string, which may not be equal to the number of characters in multi-byte character sets like UTF-8. On the other hand, CHAR_LENGTH() specifically counts the number of characters in a string, providing a more accurate result for character counting.

$query = "SELECT CHAR_LENGTH(column_name) AS character_count FROM table_name";
$result = mysqli_query($connection, $query);

if(mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        echo "Character count: " . $row['character_count'];
    }
}