For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > April 2007 > UTF8 European characters in MySQL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author UTF8 European characters in MySQL
John

2007-04-26, 7:03 pm

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


Alex

2007-04-27, 4:02 am

John wrote:

> 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.

--
Alex
e-mail: Domain is iki dot fi. Local-part is alext.
local-part at domain
John

2007-04-27, 8:02 am


"Alex" <check.sig@for.email.invalid> wrote in message
news:AfhYh.44643$bu6.43143@reader1.news.saunalahti.fi...
> John wrote:
>
>
> 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.
>
> --
> Alex
> e-mail: Domain is iki dot fi. Local-part is alext.
> local-part at domain


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ürgen Exner

2007-04-27, 7:02 pm

John wrote:
> "Alex" <check.sig@for.email.invalid> wrote in message
>
> 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


John

2007-04-27, 7:02 pm


"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:LTmYh.2$kg1.1@trndny04...
> John wrote:
>
> 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


Jürgen Exner

2007-04-27, 7:02 pm

John wrote:
> Grussgott!


If I ever meet him which is higly unlikely

jue


Alex

2007-04-27, 7:02 pm

J=FCrgen Exner wrote:

> 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=20
> utf8 is a good idea.


Or string literals, yes?
$string =3D 'Gr=FC=DF Gott';
=2E..or am I mistaken?

--=20
Alex
e-mail: Domain is iki dot fi. Local-part is alext.
local-part at domain
Jürgen Exner

2007-04-27, 7:02 pm

Alex wrote:
> Jürgen Exner wrote:
>
>
>
> Or string literals, yes?


No.

> $string = 'Grüß Gott';
> ...or am I mistaken?


Yes, you are. Just give it a try.

jue


Joe Smith

2007-04-29, 4:06 am

Alex wrote:
> Jürgen Exner wrote:
>
>
>
> 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
Alex

2007-04-30, 8:10 am

In-Reply-To: <J2oYh.9$r77.2@trndny08>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Lines: 17
Message-ID: <PVfZh.156010$061.89967@reader1.news.saunalahti.fi>
Date: Mon, 30 Apr 2007 09:21:25 +0300
NNTP-Posting-Host: 193.138.126.203
X-Complaints-To: newsmaster@saunalahti.com
X-Trace: reader1.news.saunalahti.fi 1177914095 193.138.126.203 (Mon, 30 Apr 2007 09:21:35 EEST)
NNTP-Posting-Date: Mon, 30 Apr 2007 09:21:35 EEST
Organization: Saunalahti Customer
Xref: number1.nntp.dca.giganews.com comp.lang.perl.misc:629339

J=FCrgen Exner wrote:

>=20
> 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.

--=20
Alex
e-mail: Domain is iki dot fi. Local-part is alext.
local-part at domain
Sherm Pendley

2007-04-30, 8:10 am

Alex <check.sig@for.email.invalid> writes:

> Jürgen Exner wrote:
>
>
> 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.


Did you try actually *reading* 'perldoc utf8'?

It makes Perl aware that your source code is utf8. It has nothing to do
with your terminal.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
Alex

2007-04-30, 8:10 am

Sherm Pendley wrote:

> Did you try actually *reading* 'perldoc utf8'?


Yes.

> It makes Perl aware that your source code is utf8. It has nothing to do
> with your terminal.


Yes, I am aware of that and I didn't say it has. It does, however, have
an impact on how UTF-8 string are printed in the terminal (which uses
UTF-8).

--
Alex
e-mail: Domain is iki dot fi. Local-part is alext.
local-part at domain
John

2007-04-30, 7:03 pm

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



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com