This article describes how to connect to a PostgreSQL database using Perl's DBI (Database Interface) module.
The DBI module enables your Perl scripts to connect to PostgreSQL databases.
To connect to PostgreSQL using the DBI module, follow these steps:
use DBI; $myConnection = DBI->connect("DBI:Pg:dbname=dbname;host=localhost", "username", "password");
After the code connects to PostgreSQL and selects the database, you can run SQL queries and perform other operations. For example, the following Perl code runs a SQL query that extracts the last names from the employees table, and stores the result in the $result variable:
$query = $myConnection->prepare("SELECT lastname FROM employees"); $result = $query->execute();
To view the online documentation for Perl's DBI, please visit http://dbi.perl.org/docs.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.