注意:要设定编码。

点击(此处)折叠或打开

  1. #! /usr/bin/env perl

  2. use strict;

  3. use warnings;

  4. use DBI;

  5. my $hostname = "xxx";
  6. my $database = "xxx";
  7. my $username = "xxx";
  8. my $userpass = "xxx";

  9. my $dbh = DBI->connect("dbi:mysql:$database:$hostname:3306", $username, $userpass);

  10. $dbh->do("SET character_set_client='utf8'");
  11. $dbh->do("SET character_set_connection='utf8'");
  12. $dbh->do("SET character_set_results='utf8'");

  13. my $sth = $dbh->prepare("select foo_01, foo_02 from foo_table");

  14. $sth->execute();

  15. while (my $row = $sth->fetchrow_hashref())
  16. {
  17.     print $row->{'foo_01'};
  18.     print "\t";
  19.     print $row->{'foo_02'};
  20.     print "\n";
  21. }

09-27 10:11