Why does PHP store characters such as Japanese in MySQL table that supports utf8 as something else but successfully reads the value back out from MySQL as the original string?
E.g.
$db = new mysqli("localhost", "user", "pwd", "test");
$sql = "INSERT INTO testtable(name) VALUES ('ボーナスエリア');
From workbench this has been inserted into the table as ディション
I have no idea how or at what level that encoding/mapping happens.
Reading it back out in PHP results in the correct string ボーナスエリア being displayed on the webpage.
Why and how does that work?
UPDATE
Thanks for all the comments so far.
More than just being curious it actually causes me a problem wanting to insert chars from another source i.e. Java which through jdbc inserts CJK chars correctly. This causes a problem in PHP reading them back out and displaying as ??????
Can anybody prove what encoding translates the characters given into what appears in db viewer?
UPDATE 2
My browser (which has nothing to do with this problem as value is ???? before it displays) is firefox with encoding set to Western ISO-8859-1. I can see Japanese characters display correctly next to ????? characters. Paradoxically, the characters that appear as ???? appear correctly in the db viewer.
Browser Settings

Web page snippet

PHP treats text mostly as arbitrary binary data. This means that in these cases it’s quite common for two errors to cancel each other out.
For example, if you write
ボーナスエリアin a source file and save it in UTF-8, what PHP sees are the bytes\xe3\x83\x9c\xe3\x83\xbc...and that’s what it will work with. You can pass that string to a database client library, like here tomysqli, and, if you are lucky, when you later get the text back from the database the client library will return the exact same bytes to PHP. Independently of how the database actually stored the data.What seems to be happening here is that the database client library is configured to interpret the data PHP hands to it according to latin1, which means that it interprets the bytes
\xe3\x83\x9c...as the charactersデ..., and that’s what the database will store. When you read the data the same thing happens: the client obtains the charactersデ...from the database, and since it’s set to encode them in latin1, it will returns\xe3\x83\x9c...to PHP. This explains how you can have mojibake in the database, but the PHP application still seems to work fine.Of course, it would be better to have the database store the text in a readable format. For that you have to set the client encoding (see mysqli_set_charset) and the database column encoding (see MySQL documentation) to to
utf8.