Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

A UTF8 round trip with MySQL

by clinton (Priest)
on Jun 12, 2007 at 19:43 UTC ( [id://620803]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    
                    Manual, or with              Automatic with 
    ...
    ¦ Console ¦ <<-encode_utf8()--- ¦ strings ¦ <<-decode_utf8()--- ¦ MySQ
    +L DB ¦
     ---------                       ---------                       -----
    +-----
    
  2. or download this
    
        CREATE TABLE test_db.test ( string VARCHAR(50) ) CHARACTER SET utf
    +8;
    
  3. or download this
    
        use Encode qw( decode_utf8 );
        my $string      = <>;
        my $utf8_string = decode_utf8($string);
    
  4. or download this
    
       use Encode qw( decode );
       my $iso_8859_string = <>;
       my $utf8_string     = decode('ISO-8859-1',$iso_8859_string);
    
  5. or download this
    
        use utf8;         # Tells Perl that the script itself is written i
    +n UTF-8
    
        my $utf8_string = "UTF-8 string with special chars: ñ æ ô";
    
  6. or download this
    
        use DBI();
    ...
                                {mysql_enable_utf8 => 1}
        );
    
  7. or download this
    
        $dbh->do('INSERT INTO test_db.test VALUES(?)', $utf8_string);
    ...
        $dbh->do('SELECT string FROM test_db.test LIMIT 1');
        my $new_string = $dbh->fetchrow_arrayref->[0];
    
  8. or download this
    
        use Encode qw( encode_utf8 );
    ...
        binmode (STDIN,':utf8');
        print $new_string;
    
  9. or download this
    
        use Encode qw( encode );
        print Encode::encode('ISO-8859-1', $new_string);
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://620803]
Approved by planetscape
Front-paged by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-25 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found