Jump to content

php 5 & Mysql 5 display problem


realjumper

Recommended Posts

Hi,

I cannot seem to display any Japanese text that comes from the db. The pgae encoding is correct - shitf jis - and any hard coded text displays just fine. I have tried all manner of collation combinations for the db and the tables, but nothing seems to work. the results displayed range from a seies of question marks...????????....to some sort of 2 byte characters being displayed, but not the correct ones. From what I have been able to find out via google, both the table and the db collations should be utf8_general_ci, which doesn't work. I have tried many other combinations of ujis etc etc, but nothing seems to return the correct charaters to the web page. This was previously working well on older versions of php and mysql, but since the update to the '5' versions I have been in this jam. If anyone can help I would apprecitate it very much.

Thanks,
Neil
Link to comment
Share on other sites

Here is the answer:

The database was and is set up like so:
Collation - utf8_unicode_ci

The tables were and are set up like so:
Collation - utf8_general_ci

The html page encoding was and is set up like so:
....content=text/html; charset=sjis


The problem was that hard coded Japanese would render correctly in the browser, but anything retrieved from the db came back as ??????. If I changed the encoding on the page to 'utf8' or 'default', the hard coded Japanese would become unreadable, but the db would return the correct Japanese record.

If, through my html page, I inserted data in the db, the inserted data was just a jumble of characters BUT a select query would return the correct Japanese record. So, the hard coded Japanese AND the data from the table rendered correctly, BUT the data was unreadable via PhpMyAdmin.....so that was not satisfactory.

However, by adding.....mysql_query("SET CHARACTER SET sjis"); immediatlely below my connection string, the problem went away and everything is just perfect.....yipee!!

Just why PHP5 and/or Mysql5 require this I don't know, and I guess no one here does either as I recieved no responses to my question.

So anyway, if anyone is interested, if the tables and the db collation is set as I have described above, AND mysql_query("SET CHARACTER SET sjis"); is put right under your connection string, you should be fine. Of course if you want to add a different character set to the string you could replace sjis with utf8 or whatever.

Hope this helps somebody
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.