Click to See Complete Forum and Search --> : Saving UTF8_bin strings properly on MySQL


Andrex
March 15th, 2007, 10:16 PM
Hi,
I'm using MySQL and phpMyAdmin with tables and collation using the UTF8_bin encoding. I'm storing strings from a webpage form with PHP, with the UTF8 charset content-type specification.

Strings are always displayed correctly on the webpage, but are not saved right on the database. For example, the spanish word árbol becomes árbol in the database. Yet it's always displayed right on the webpages, but on the database it takes an extra character thus reducing the actual string capacity.

The question is, how do I save these strings with accents (I'm not needing to save greek or arabic, yet that would be good) properly on the tables, and if PHP should make the conversion, how to do it.

Thanks in advance.

RhinoBull
March 22nd, 2007, 08:57 AM
I'm not familiar with MySql however I do have similar problem with Oracle.
The problem (in my case) is that when it was installed on the server it wasn't configured to as UTF based so there is no way to save correct unicode chars unless system is rebuilt wich isn't going to happen.
Since I only care about few special chars like [® © ™] my solution was to replace those before data is saved with actual char number presented as text:

® --> "chr(174)"

when you read back from DB you will simply convert it back

"chr(174)" --> ®

But as I said I only had few to worry about...