Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delphi to mysql to html

Posted on 2012-04-12
6
Medium Priority
?
480 Views
Last Modified: 2012-04-26
A user enters text into a Delphi program, Delphi puts it into a MySQL table. The charset is latin1. The collation is latin1_swedish_ci.

Then php put the data on a web page. Now there is a problem, Swedish characters turns into garbage. This probably can be fixed in the php end, but I would prefer that MySQL took care of this. MySql knows the charset and the collation, so I am looking for some MySQL command that translates this into HTML before it leaves the MySQL server.
0
Comment
Question by:Sunsales
6 Comments
 
LVL 24

Expert Comment

by:johanntagle
ID: 37840788
I don't know of any existing mysql function that does this (you can find all available string functions at http://dev.mysql.com/doc/refman/5.5/en/string-functions.html).

On the web page I think it is only a matter of setting the correct charset on the header.  Something like Content-Type: text/plain; charset=ISO-8859-1
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 37841279
a database is a data storage/calculation device, not a display device

it is up to the display device to show things the way things should be shown
just imagine internet explorer automatically displaying all languages in chinees
> trying to solve this in the database wouldn't get you anywhere

displaying is a matter of correctly translating
> the database has no clue what language is used in the display device
0
 

Author Comment

by:Sunsales
ID: 37841380
> the database has no clue what language is used in the display device

The database collation is set to "latin1_swedish_ci", so the database knows what language is used, the theoretical either a php or a mysql functon is used to encode this to html. I don't see any harm in the MySQL team add a function to encode into html, it might even make MySQL more popular. Something like:

HtmlEncoded Select  * from TableAlfa where ....;


But when no such function exists, then il guess that PHP better take care of it.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 24

Expert Comment

by:johanntagle
ID: 37841409
Actually I think it will harm the reputation of the MySQL team if they prioritize adding such a feature over other more needed fixes.  Also, I doubt if it will be a popular feature, because the recommended practice is to decouple functionality, i.e. keep business/data logic and presentation logic separate.  This will also allow you to easily customize presentation to different types of devices i.e. desktop vs mobile browsers.

Please also note that the display of international characters also depends on what the page tells the browser what character set the content uses and whether the browser can support it.  This is clearly the business of presentation code.
0
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 1600 total points
ID: 37841484
you set the collation to latin1_swedish_ci
> this means that a mapping will occur to this character set
the mapping is usually done by the client which has been configured to "know" what "the character set for displaying" (A) and "the character set in the db is" (B)

you can actually fool the client into believing that chinese (for "A) is actually swedish so it doesn't do any mapping
> this way you can store "chinese" in a swedish database
>> off course, when you use a client which hasn't been "fooled around with" it will do incorrect mappings and the display device will show garbage on screen
0
 
LVL 9

Expert Comment

by:rinfo
ID: 37842408
Try iconv while sending data to php.
you have to install iconv module.

iconv("ISO-8859-1,"UTF-8" //TRANSLIT", $yourdata);

However best thing would be to try and  mysql for UTF8 instead of latin1;
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question