Skip to main content
Participant
April 24, 2007
Question

Retaining unicode from db to browser

  • April 24, 2007
  • 4 replies
  • 632 views
The UTF-8 encoded data in my MySQL database does not retain the unicode format in cfoutput. I was able to copy unicode data from the database and paste it directly into a test HTML page that had the appropriate meta/content tags to verify that original language displays properly in several browsers. However, when I query the data via cfquery, the data appears to convert to Western or perhaps a default character set, not the original unicode stored in the database.

What controls the format used when outputing data from a db? Seems like the cfoutput tag should have a "characterset" parameter.

Thanks for your insights.

-Malconverted
This topic has been closed for replies.

4 replies

Inspiring
April 24, 2007
junyong@mynetiquette.com wrote:

> default-character-set=utf8 (default is latin1). restart your mysql server and
> try and see.
>

i wonder how is he gonna do that on a shared host...

you DO have to add the line
"?useUnicode=true&characterEncoding=utf8" (without the quotes!)
to the end of the jdbc url in the dsn setup page in cf admin. you
probably can't do it yourself on a shared server since you are unlikely
to have access to CF Administrator, but if you ask your hosting company
i am sure they will do it for you.

also, add the following into your Application.cfm:

<cfscript>
SetEncoding("form","utf-8");
SetEncoding("url","utf-8");
</cfscript>
<cfcontent type="text/html; charset=utf-8">

and on every page that displays unicode data from db add the line:
<cfprocessingdirective pageencoding="utf-8">

at the top of the page.

also make sure there are no conflicting charsets are set in meta tags...
--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Inspiring
June 21, 2007
Thank you for your very helpful replies. I'm just picking this issue back up again...

My hosting company said they can't add the line "?useUnicode=true&characterEncoding=utf8"
to the end of the jdbc url in the dsn setup page in cf admin, because it would impact everyone in the virtual environment, of course. They also said they run only ODBC drivers and are not planning to use JDBC drivers.

Is my only option to go with a dedicated server? I want to avoid the expense if I can. Are there virtual environments that offer more flexibility. I'm currently with UplinkEarth. Has anyone been successful delivering unicode characters in a virtual environment?
Inspiring
April 24, 2007
your cf must be 6 or above and your jdbc for mysql should be 3.17 or above. you dont have to amend any utf-8 setting in the jdbc driver because it is integrated by default. Open your my.ini and reset this argument.

default-character-set=utf8 (default is latin1). restart your mysql server and try and see.
msalvAuthor
Participant
April 24, 2007
I'm running MX in a virtual environment; ISP service (UplinkEarth).
Inspiring
April 24, 2007
msalv wrote:
> The UTF-8 encoded data in my MySQL database does not retain the unicode format
> in cfoutput. I was able to copy unicode data from the database and paste it

what ver of cf? it has to be at least 6. what db driver? it should be JDBC & you
need to add "useUnicode=true&characterEncoding=utf8" for the JDBC url via the
"advanced" menu for that DSN.