close

#! /usr/bin/perl
use DBI();
# Connect to the database
my $db="dbname";
my $host='dbhost'
my $user='dbuser';
my $password='passwd';
#my $query=shift;
my $dbh = DBI->connect("DBI:mysql:database=$db;host=$host",
                                          $user, $password,
                                          {RaiseError => 1})
                                       || die "Database connection not made: $DBI::errstr";


$sth = $dbh->prepare("select * from table where colunm='match-string'");

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

$sth->execute;

while ( @row = $sth->fetchrow_array() ) {
print "@row\n";
}

$sth->finish();
# Disconnect from the database.
$dbh->disconnect();

Ref:http://dev.mysql.com/doc/refman/5.0/en/charset-general.html

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 hweily 的頭像
    hweily

    hweily

    hweily 發表在 痞客邦 留言(0) 人氣()