"Perl DBD::Pg()"의 두 판 사이의 차이

6번째 줄: 6번째 줄:
{{참고|cpanm|펄 모듈 설치}}
{{참고|cpanm|펄 모듈 설치}}
=== 필요한 의존성 ===
=== 필요한 의존성 ===
; PostgresSQL
[[Postgresql 설치]] 참고.
; DBI
; DBI
<source lang='console'>
<source lang='console'>
16번째 줄: 19번째 줄:
1 distribution installed
1 distribution installed
</source>
</source>
=== 모듈 설치 ===
=== 모듈 설치 ===
; <nowiki>DBD::Pg</nowiki>
; <nowiki>DBD::Pg</nowiki>

2018년 4월 23일 (월) 17:01 판

1 개요

DBD::Pg는 DBI 모듈을 위한 PostgreSQL 데이터베이스 드라이버로서 펄 모듈의 하나이다.

2 설치

2.1 필요한 의존성

PostgresSQL

Postgresql 설치 참고.

DBI
$ 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
$ 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 사용법

  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 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}