Program Listings

Listing 2-1 contains the complete and uninterrupted code from this chapter.

Listing 2-1: connect_multi.pl

start example
01: #!/usr/bin/perl -w 02: # 03: # connect_multi.pl 04: # Chapter 2 05: # Listing 2 06: use strict; 07: use DBI; 08: my $dbh_m =         DBI->connect("dBi:mysql:quizzer:dbserver.perlguy.net",        "bookuser",         "password")  09:     or die("Cannot connect: $DBI::errstr\n"); 10: my $dbh_p = DBI->connect("dbi:Pg:dbname=test",         "postgres","")  11:     or die("Cannot connect: $DBI::errstr\n"); 12: my $sql = qq(select * from test_config); 13: my $sth_m = $dbh_m->prepare($sql); 14: my $sth_p = $dbh_p->prepare($sql); 15: $sth_m->execute; 16: $sth_p->execute; 17: while(my $p = $sth_m->fetch){ 18:   print "MySQL: @$p\n"; 19: } 20: print "\n"; 21: while(my $p = $sth_p->fetch){ 22:   print "PostGreSQL: @$p\n"; 23: } 24: $dbh_m->disconnect; 25: $dbh_p->disconnect;
end example



Perl Database Programming
Perl Database Programming
ISBN: 0764549561
EAN: 2147483647
Year: 2001
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net