Forum Moderators: open

Message Too Old, No Replies

Storing UTF8 bin characters properly

         

Jakotsu

2:11 am on Mar 16, 2007 (gmt 0)

10+ Year Member



I'm using MySQL and phpMyAdmin with tables and collation using the UTF8_bin encoding. I'm storing strings from a webpage 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.

The question is how do I save these strings with accents properly on the tables, and if PHP should make the conversion, how to do it.

Thanks in advance.

physics

6:57 am on Mar 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What are you using to view the database entries?

souFrag

9:19 pm on Mar 27, 2007 (gmt 0)

10+ Year Member



I'm having the same problem.

First I posted data from a form in a UTF-8 PHP/XHTML page and then stored it on a MySQL database using adodb.

Example of posted text:
árbol

Then, if I see the MySQL DB using phpMyAdmin, the text is shown as:
árbol

BUT, if I see the text from a UTF-8 PHP/XHTML file (UTF-8 encoded and correct UTF-8 meta tag) it is shown correctly (árbol).

¿Is the data been saved correctly?
¿Is it phpMyAdmin problem?... ¿Or am I doing something wrong?

Thx.

Clark

3:49 am on Mar 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sounds like a phpmyadmin problem to me. And I have some similar issues with them too.

souFrag

10:16 pm on Mar 28, 2007 (gmt 0)

10+ Year Member



I've found the solution.

Using ADOdb:


$db_charset = $conn->Execute( "SHOW VARIABLES LIKE 'character_set_database'" );
$conn->Execute( "SET NAMES '" . $db_charset->fields['Value'] . "'" );
$db_charset->Close();

You could also use something simpler like:


@mysql_query("SET NAMES 'utf-8'");

[edited by: rogerd at 11:11 pm (utc) on Mar. 28, 2007]
[edit reason] No URLs, please... [/edit]

Clark

10:57 pm on Mar 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good work. The url you pointed to will probably be removed though. Try to figure out what search terms to go after in google to find that solution, which is the accepted way to do that here.

[edited by: Clark at 10:58 pm (utc) on Mar. 28, 2007]

souFrag

3:48 am on Mar 29, 2007 (gmt 0)

10+ Year Member



sorry, i didn't know i couldn't post url's in this forums :-)

i just registered here to post this question (and then the answer.. lol)
i've alredy posted the solution, but if you want a larger explanation, try searching google for something like "SET NAMES '" . $db_charset->fields['Value'] . "'"