Client 1—Connecting to the Server

Before you try to connect to a PostgreSQL server, take a moment to examine the basic components of a typical Perl/DBI script.

Listing 14.1 shows a Perl script that will print the list of available DBD drivers.

Listing 14.1. get_drivers.pl
 1 #!/usr/bin/perl -W
 2 #
 3 #  Filename: get_drivers.pl
 4 #
 5 use strict;
 6 use DBI;
 7
 8 # Get the list of drivers from the DBI
 9 #
10 my @driver_names = DBI->available_drivers();
11 
12 # Print the name of each driver
13 #
14 foreach my $driver ( @driver_names ) {
15     print( "Driver: $driver\n" );
16 }

The first line of the script identifies this file as an executable. When you run a program on Unix/Linux systems, or if you are using Cygwin in the Windows environment, a script ...

Get PostgreSQL, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.