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