UTF8 European characters in MySQL

J

John

Hi

I have created a table with

DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

However, the European accented characters appear incorrectly.

What is the standard accepted way to read/write European accented characters
in Perl using MySql database?

Regards
John
 
A

Alex

John said:
I have created a table with

DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

However, the European accented characters appear incorrectly.

A little more information would be helpful. What do they look like? How
do you view them? ( in mysql's cli, in html, etc.?) What are your locale
settings? Do you 'use utf8' in you perl script? What system are you
running your script on?
What is the standard accepted way to read/write European accented characters
in Perl using MySql database?

Utf-8 is the new one. ISO-8859-1 (or ISO-8859-15) is the old one and
still works, but is restricted to western characters.
 
J

John

Alex said:
A little more information would be helpful. What do they look like? How
do you view them? ( in mysql's cli, in html, etc.?) What are your locale
settings? Do you 'use utf8' in you perl script? What system are you
running your script on?


Utf-8 is the new one. ISO-8859-1 (or ISO-8859-15) is the old one and
still works, but is restricted to western characters.

Many thanks. No, I don't have "use utf8" so I need to look at this package.
It probably is the answer. Thanks

Regards
John
 
J

Jürgen Exner

John said:
Many thanks. No, I don't have "use utf8" so I need to look at this
package. It probably is the answer.

No, it isn't and you don't.

perldoc utf8:
utf8 - Perl pragma to enable/disable UTF-8 in source code


Do you want to use e.g. variable names that are non-ASCII? If yes, then use
utf8 is a good idea.

But it has nothing to do with the _data_ that is processed by the Perl
program.

jue
 
J

John

Jürgen Exner said:
No, it isn't and you don't.

perldoc utf8:
utf8 - Perl pragma to enable/disable UTF-8 in source code


Do you want to use e.g. variable names that are non-ASCII? If yes, then
use utf8 is a good idea.

But it has nothing to do with the _data_ that is processed by the Perl
program.

jue
Grussgott!

I am now making a little progress with decode_utf8.
I think I am almost there.

Viel spass.
John
 
A

Alex

Jürgen Exner said:
perldoc utf8:
utf8 - Perl pragma to enable/disable UTF-8 in source code
Do you want to use e.g. variable names that are non-ASCII? If yes, thenuse
utf8 is a good idea.

Or string literals, yes?
$string = 'Grüß Gott';
...or am I mistaken?
 
J

Joe Smith

Alex said:
Or string literals, yes?
$string = 'Grüß Gott';

Yes, if your program file is in UTF8 format. (Simply containing non-ASCII
characters does not automatically mean UTF8). As shown in "perldoc utf8":

Enabling the "utf8" pragma has the following effect:

· Bytes in the source text that have their high-bit set will be
treated as being part of a literal UTF-8 character. This
includes most literals such as identifier names, string constants,
and constant regular expression patterns.

Perl program containing non-ASCII characters in the source code that are
part of the ISO-8859-15 character set and are stored as one byte per
character: don't "use utf8;".

Source code containing non-ASCII characters stored as multiple bytes
per character (by a UFT8-aware editor and/or file system): yes, "use utf8;".

-Joe
 
A

Alex

Jürgen Exner said:
Yes, you are. Just give it a try.

Did give it a try and omitting 'use utf8' has a remarkable difference,
eg. when printing to the terminal. If I don't use utf8, string functions
like length() work incorrectly. If I do use utf8, Perl must be made
aware that I'm using a UTF-8 terminal. Otherwise it's question marks
galore. It seems easier to "use encoding 'utf8'" instead, however.
 
J

John

Hi

I've got it working.

I've puilled out the key features for others who may have a similar problem.

<meta http-equiv='content-type' content='text/html;
charset=ISO-8859-1'></meta>

# create table
my $sql="SET CHARACTER SET utf8";
$sql="SET NAMES utf8";
$sql="CREATE TABLE $table (id integer auto_increment not null primary
key,username varchar(40),";
$sql.="CheckIn varchar(20),CheckOut varchar(20)"; etc etc
$sql.="DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";

# read table
use Encode;
$HotelName=decode_utf8($HotelName); # may contain accented characters

Regards
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top