#!/usr/local/bin/perl -w # NOTE --- NEED /usr/local/bin/perl, NOT /usr/bin/perl, on sorrel # for this to work!!!!! # so, we may be using these modules: use DBI; use CGI qw/ :standard /; # set necessary environment variables # ... this is sorrel's: $ENV{'ORACLE_HOME'} = '/apps1/oracle/product/9iAS/'; # ...and so is this: $ENV{'LD_LIBRARY_PATH'} = '/apps1/oracle/product/9iAS/lib'; my $db_handle = DBI->connect('Student', 'perlplay', 'perlplay', 'Oracle') || die "Database connection not made: $DBI::errstr"; # this is simply the SQL command that I wish to run my $sql_cmd = 'select empl_last_name, job_title from empl'; # this sets up a statement handle for that SQL command $stmt_handle = $db_handle->prepare( $sql_cmd ); # this executes the SQL statement $stmt_handle->execute(); # ...and now you can use the statement handle to fetch the resulting # rows. # Here, I'm reading the first name/job_title pair only... ($emp_name, $emp_title) = $stmt_handle->fetchrow_array(); print "name: $emp_name, job_title: $emp_title\n"; # IF I am not grabbing all of the rows from the executed statement # handle, I should probably finish that handle before disconnecting # the database handle: $stmt_handle->finish; $db_handle->disconnect; # end of dbi2