注意:要设定编码。
点击(此处)折叠或打开
- #! /usr/bin/env perl
- use strict;
- use warnings;
- use DBI;
- my $hostname = "xxx";
- my $database = "xxx";
- my $username = "xxx";
- my $userpass = "xxx";
- my $dbh = DBI->connect("dbi:mysql:$database:$hostname:3306", $username, $userpass);
- $dbh->do("SET character_set_client='utf8'");
- $dbh->do("SET character_set_connection='utf8'");
- $dbh->do("SET character_set_results='utf8'");
- my $sth = $dbh->prepare("select foo_01, foo_02 from foo_table");
- $sth->execute();
- while (my $row = $sth->fetchrow_hashref())
- {
- print $row->{'foo_01'};
- print "\t";
- print $row->{'foo_02'};
- print "\n";
- }