What am I doing wrong? I have followed the perldoc DBD::DB2 and even copies the
example from the documentation (no plagerism intended =) ) I have have no problems
sending the information to the database if I don't use databinding. I would really
really prefer to use databinding in the loop instead of calling the whole prepare line
each time. Here is what I am doing:
____________________________
#!/usr/bin/perl -wT
use DBI;
use DBD::DB2::Constants;
use DBD::DB2;
use CGI;
use CGI::Carp qw( fatalsToBrowser );
use strict;
#Sets the DB2 instance user: give authority for "nobody" to connect to DB2
$ENV{DB2INSTANCE}='db2inst1';
#Cleans up the $ENV, gets rid of risky environmental variables.
$ENV{PATH} = "/bin:/usr/bin";
delete @ENV{ 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
#Defines the database we are going to use.
#DPS LOCAL DATABASE
my $dbi_source_1 = 'dbi:DB2:SWPERMIT';
my $dbi_loginname_1 = 'db2inst1';
my $dbi_loginpass_1 = 'onlymine';
#Sets up our CGI environment.
my $q = new CGI;
my $dbh;
#Sets the debuggin level for DBI handles that use %attr.
my %attr = (
PrintError => 0,
RaiseError => 1,
AutoCommit => 0
);
my %listvalues;
my $sth8 = $dbh->prepare( "SELECT TABLELIST
FROM SWP_TABLELIST
WHERE IS_ACTIVE = TRUE_FALSE(1)
AND IS_REQUIRED = TRUE_FALSE(0)" );
$sth8->execute();
while (my ( $temp4 ) = $sth8->fetchrow_array ) { push @listvalues, $temp4; }
#Set up stuff for DBI call.
my @seqlist;
for ( my $i = 0; $i <= @listvalues; $i++ ) {
my $sth2 = $dbh->prepare( 'SELECT newkey
FROM db2inst1.SEQUENCE' );
$sth2->execute();
$seqlist[$i] = $sth2->fetchrow_array();
}
#DB2 Perldoc example
my ( $tabseq, $tablist, $order, $instval );
my $sth->prepare( "INSERT INTO db2inst1.SWP_LINKTABLELIST( LINKTABLELISTSEQ,
TABLELISTSEQ, TRIPSEQ, CGIORDER )
VALUES (?, ?, ?, ? )" );
for( my $i=0; $i <= @listvalues; $i++ ) {
$tabseq = $seqlist[$i+1]; # set a new value
my $quote_listvalues = $listvalues[$i];
#Have to do the SQL call outside of the SQL insert to make this type of
call work.
my $sth100->prepare( "SELECT TABLELISTSEQ FROM db2inst1.SWP_TABLELIST
WHERE TABLELIST = $quote_listvalues" );
$sth100->execute;
$tablist = $sth100->fetchrow_array();
$order = $i + 1;
#Now we bind the declared variables
$sth->bind_param( 1, \$tabseq );
$sth->bind_param( 2, \$tablist );
$sth->bind_param( 3, \$seqlist[0] );
$sth->bind_param( 4, \$order );
#Now execute the statement to DB2.
$sth->execute();
}
print $q->header( "text/html" ),
$q->start_html( -title => "Successfully tested database", -bgcolor =>
"#FFFFFF" ),
$q->h2( "Success..." ),
$q->end_html;
_____________________________________________________
The error I get from apache is:
[Fri Jan 6 22:58:11 2002] [error] Can't call method "prepare" on an undefined value
at /usr/perl/cgi/permit_organization.cgi line 74.
When I print out the values of my variables there are no 'nulls' or '0' values.
Thanks in advance.
Bobby