Is PHP memory inefficient at string management?

Today I had a problem with PHP and MySQL ( here is the question ), which was already resolved, but it aroused a new, more theoretical question.

The fact is that in the MySQL database I had a field whose type was VARCHAR(64) . When trying to insert a string from a PHP script, the complete string was more than 64 bytes, which makes var_dump proved that it has 71. BUT, that’s what I don’t understand, executing the same query, with exactly the same string, but manually from phpmyadmin , it fit into a 64-byte sql field.

So here is the question. Is there a reason why the same line in php takes up more memory than pasting it directly into the database?

EDIT: Someone suggested a duplicate of the encoding related question. The encoding in MySQL is utf8_general_ci. In PHP, I did not define the encoding, but if I di print(mb_detect_encoding($string)); I will get its ASCII encoding. Maybe this is the reason? How am I mistaken if I believe that ASCII takes up less memory than utf8? (Anyway, in the script, I have mysqli_set_charset($con,"utf8"); so it must be converted to utf8 before the request)

+6
source share

All Articles