Re: using $dbh->quote with UTF
- From: martin.evans@xxxxxxxxxxxx (Martin Evans)
- Date: Thu, 18 Oct 2007 09:02:28 +0100
len@xxxxxxxxxxxxx wrote:
Hello,
I'm trying to use $dbh->quote with a UTF string, and I'm not having
luck. How can I get it to return a UTF8 string?
Here is my example:
#!/usr/bin/perl -w
use strict;
Add use warnings;
use DBI;If you add use warnings I suspect your print will issue:
my $dbh = DBI->connect("DBI:mysql:mysql", "root", "");
my $string = "test äñèé";
utf8::upgrade($string);
my $sqlutfstring = $dbh->quote($string);
print qq~
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf8">
<title>UTF Quote Test</title>
</head>
<body>
~;
print $string . " == " . $sqlutfstring;
print qq~
</body>
</html>
~;
Wide character in print at xxx, which might have given you the clue that I believe you should do binmode(STDOUT, ":utf8") before you print.
quote seems to work for me:
perl -e 'use DBI qw(neat);$h=DBI->connect("dbi:Oracle:XE","xxx","yyy");$x="\x{20ac}";open OUT, ">x.x";binmode(OUT,":utf8");print OUT $x;close OUT;print neat($x);'
"€"
and as neat has put double quotes around the Euro, then DBI thinks it is a unicode character too.
Martin
--
Martin J. Evans
Easysoft Limited
http://www.easysoft.com
.
- Follow-Ups:
- Re: using $dbh->quote with UTF
- From: Len@xxxxxxxxxxxxx
- Re: using $dbh->quote with UTF
- References:
- using $dbh->quote with UTF
- From: Len@xxxxxxxxxxxxx
- using $dbh->quote with UTF
- Prev by Date: using $dbh->quote with UTF
- Next by Date: Problems Compiling DB2 DBD
- Previous by thread: using $dbh->quote with UTF
- Next by thread: Re: using $dbh->quote with UTF
- Index(es):