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

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 5개는 보이지 않습니다)
4번째 줄: 4번째 줄:


== 설치 ==
== 설치 ==
{{참고|cpanm|펄 모듈 설치}}
=== 필요한 의존성 ===
=== 필요한 의존성 ===
; PostgresSQL
[[Postgresql 설치]] 참고.
; DBI
; DBI
<source lang='console'>
<syntaxhighlight lang='console'>
$ cpanm --notest DBI
$ cpanm --notest DBI
--> Working on DBI
--> Working on DBI
14번째 줄: 18번째 줄:
Successfully installed DBI-1.641
Successfully installed DBI-1.641
1 distribution installed
1 distribution installed
</source>
</syntaxhighlight>
 
=== 모듈 설치 ===
=== 모듈 설치 ===
; <nowiki>DBD::Pg</nowiki>
; <nowiki>DBD::Pg</nowiki>
<source lang='console'>
<syntaxhighlight lang='console'>
$ export POSTGRES_HOME=/home/user/pg
$ export POSTGRES_HOME=/home/user/pg
$ cpanm --notest  DBD::Pg
$ cpanm --notest  DBD::Pg
26번째 줄: 31번째 줄:
Successfully installed DBD-Pg-3.7.4
Successfully installed DBD-Pg-3.7.4
1 distribution installed
1 distribution installed
</source>
</syntaxhighlight>
POSTGRES_HOME 환경 변수가 지정되지 않으면 모듈이 올바르게 설치되지 않는다.
<code>POSTGRES_HOME</code> 환경 변수가 지정되지 않으면 모듈이 올바르게 설치되지 않는다.


== 사용법 ==
== 사용법 ==
<source lang='perl'>
<syntaxhighlight lang='perl'>
   use DBI;
   use DBI;
   use DBD::Pg qw(:pg_types);  # pg type 값이 필요한 경우 (:pg_types)를 지정
   use DBD::Pg qw(:pg_types);  # pg type 값이 필요한 경우 (:pg_types)를 지정
   use DBD::Pg qw(:async); # 비동기 호출의 경우 async constant를 지정0
   use DBD::Pg qw(:async); # 비동기 호출의 경우 async constant를 지정


   my $dbname = "zetawiki";
   my $dbname = "zetawiki";
45번째 줄: 50번째 줄:
   $sth = $dbh->prepare('INSERT INTO mytable(a) VALUES (?)');
   $sth = $dbh->prepare('INSERT INTO mytable(a) VALUES (?)');
   $sth->execute();
   $sth->execute();
</source>
</syntaxhighlight>


== 참고 ==
== 참고 ==
* http://search.cpan.org/dist/DBD-Pg/Pg.pm
* http://search.cpan.org/dist/DBD-Pg/Pg.pm


[[분류:Perl]]
[[분류:Perl 모듈]]

2020년 11월 2일 (월) 02:55 기준 최신판

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 }}