1 개요[ | ]
DBD::Pg는 DBI 모듈을 위한 PostgreSQL 데이터베이스 드라이버로서 펄 모듈의 하나이다.
2 설치[ | ]
2.1 필요한 의존성[ | ]
- PostgresSQL
Postgresql 설치 참고.
- DBI
Console
Copy
$ cpanm --notest DBI
--> Working on DBI
Fetching http://www.cpan.org/authors/id/T/TI/TIMB/DBI-1.641.tar.gz ... OK
Configuring DBI-1.641 ... OK
Building DBI-1.641 ... OK
Successfully installed DBI-1.641
1 distribution installed
2.2 모듈 설치[ | ]
- DBD::Pg
Console
Copy
$ export POSTGRES_HOME=/home/user/pg
$ cpanm --notest DBD::Pg
--> Working on DBD::Pg
Fetching http://www.cpan.org/authors/id/T/TU/TURNSTEP/DBD-Pg-3.7.4.tar.gz ... OK
Configuring DBD-Pg-3.7.4 ... OK
Building DBD-Pg-3.7.4 ... OK
Successfully installed DBD-Pg-3.7.4
1 distribution installed
POSTGRES_HOME
환경 변수가 지정되지 않으면 모듈이 올바르게 설치되지 않는다.
3 사용법[ | ]
Perl
Copy
use DBI;
use DBD::Pg qw(:pg_types); # pg type 값이 필요한 경우 (:pg_types)를 지정
use DBD::Pg qw(:async); # 비동기 호출의 경우 async constant를 지정
my $dbname = "zetawiki";
my $dbh;
# 오토커밋을 명시적으로 하지 않도록 설정
$dbh = DBI->connect("dbi:Pg:dbname=$dbname", '', '', {AutoCommit => 0});
# 값 1을 mytable에 INSERT
$dbh->do('INSERT INTO mytable(a) VALUES (1)');
$sth = $dbh->prepare('INSERT INTO mytable(a) VALUES (?)');
$sth->execute();
4 참고[ | ]
편집자 Ykhwong Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.