[EMAIL PROTECTED] 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;
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>
~;
If you add use warnings I suspect your print will issue:
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