User Tools

Site Tools


scratchpad:dmcmorris:dbdtest

The following is a simple Perl script to test the DBI and DBD connections.

#!/usr/bin/perl

# Constructed using the information available at
# http://www.tizag.com/perlT/perldbiquery.php
# and input from http://www.saturn5.com/~jwb/dbi-examples.html
# with modifications by dmcmorris for use as a test on the 
# Evergreen project.  http://www.open-ils.org 2007-05-24

# PERL MODULES WE WILL BE USING
use DBI;
use DBD::Pg;

# CONFIG VARIABLES
$database = "openils";
$host = "localhost";
$user = "postgres";
$pw = "evergreen";

# PERL DBI CONNECT
$connect = DBI->connect("dbi:Pg:dbname=$database;host=$host", "$user", "$pw") 
              || die "Database connection not made: $DBI::errstr";

# PREPARE THE QUERY
$query = "SELECT * FROM actor.org_unit";
$query_handle = $connect->prepare($query);

# EXECUTE THE QUERY
$query_handle->execute();

# BIND TABLE COLUMNS TO VARIABLES
$query_handle->bind_columns(
                        \$id, 
                        \$parent_ou, 
                        \$ou_type, 
                        \$ill_address, 
                        \$holds_address,
                        \$mailing_address,
                        \$billing_address,
                        \$shortname,
                        \$name,
                        \$email,
                        \$phone,
                        \$opac_visible
                        );

# LOOP THROUGH RESULTS
while($query_handle->fetch()) {
   print "$id, $shortname, $name\n";
} 
scratchpad/dmcmorris/dbdtest.txt · Last modified: 2022/02/10 13:34 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki

© 2008-2022 GPLS and others. Evergreen is open source software, freely licensed under GNU GPLv2 or later.
The Evergreen Project is a U.S. 501(c)3 non-profit organization.