PERL DB 접속하기
개발/프로그래밍2010. 12. 28. 20:53
728x90
#!/usr/bin/perl use DBI; my $dbh = DBI->connect("DBI:mysql:database=db_name;host=ip_address", "user_id", "user_password") || die "Error"; my $sql = "SELECT ITEM_TITLE FROM TB_CRAW LIMIT 50"; my $utf_sql = "set names utf8"; my $sth = $dbh->prepare($utf_sql); $sth->execute(); my $sth = $dbh->prepare($sql); $sth->execute(); while(my $row = $sth->fetchrow_hashref()){ print "TITLE: $row->{ITEM_TITLE}\n"; } $sth->finish; $dbh->disconnect();
set names utf8은 MYSQL이 UTF8 일 경우 사용하면 됨.
728x90
댓글 영역