Skip to content
PHP Logo

Is each character in a query equivalent to one byte?

In PHP, characters in a query are not necessarily equivalent to one byte. The number of bytes used to represent a character can vary depending on the character encoding being used. To ensure accurate byte count, you can use the `mb_strlen()` function with the specified character encoding.

php
$query = "SELECT * FROM users WHERE username = 'JohnDoe'";
$byteCount = mb_strlen($query, '8bit');
echo "Byte count of the query: " . $byteCount;