Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8082185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:00:06+00:00 2026-06-05T17:00:06+00:00

Why does PHP store characters such as Japanese in MySQL table that supports utf8

  • 0

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

browser settings

Web page snippet

web page snippet

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:00:09+00:00Added an answer on June 5, 2026 at 5:00 pm

    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 to mysqli, 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does it possible to execute php file and store its output into some variable?
does PHP support something like ampersand in bash (forking)? Let's say I wanted to
Does PHP supports Composite data type? If yes, then how could I create it?
Is it possible in JavaScript to do something like preg_match_all does in PHP ?
i am trying to store Chinese character in mysql database,but it store some messy
I have a mysql database table to store country name and currency symbol -
I scrape some sites that occasionally have UTF-8 characters in the title, but that
I have a database defined with charset utf8_general_ci and a table that should store
I've developed an PHP/MySQL-application where in one table names are stored. These names sometimes
Does PHP expose Apache's Mime-Type to extension mapping in any way shape or form.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.