slok has asked for the wisdom of the Perl Monks concerning the following question:
sub queryresult { my $debug = 1; # 0 to off, 1 to turn it on my $results; my $dbuser = '111'; my $dbpasswd = '222'; my $s_off_no = $s_off_no; # Query to check if driver exist my $query1 = "select veh_reg_no from offence " . "where off_no = $s_off_no"; # Database DBI driver name my $dbname = "DBI:Oracle:"; # Create database handle my $dbh = DBI->connect($dbname, $dbuser, $dbpasswd); if (!$dbh) { showSQLerror("Connecting to the database"); return; } else { # set AutoCommit 1 = ON, 0 = OFF (1 is default) # transaction control is *required* here, hence set OFF $dbh->{AutoCommit} = 0; } if ($debug == 1) { print("<br>query1: $query1"); } $results = run_statement($dbh,$query1,"Y"); if ($results == 0) { printErrors('Invalid Offence No.!'); return; } elsif ($results == -1) { $dbh->rollback; $dbh->disconnect; return; } else { $dbh->commit; $dbh->disconnect; print("<br>$results"); } } sub run_statement { my ($dbh,$sql,$getNo)=@_; my $new_offNo; # Create a statement handle - prepare the statement my $sth = $dbh->prepare($sql); if (!$sth) { showSQLerror("Preparing SQL statement"); return (-1); } # Execute the statement against the database $sth->execute; if ($DBI::errstr) { showSQLerror("Executing SQL Statment"); $sth->finish; return (-1); } print("<br>sql : $sql<br>"); if ($getNo eq "Y") { ($new_offNo) = $sth->fetchrow; } else { $new_offNo = 0; } $sth->finish; return ($new_offNo); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI or DBI 'cache' problem
by chromatic (Archbishop) on May 13, 2002 at 03:25 UTC | |
by slok (Acolyte) on May 13, 2002 at 04:41 UTC | |
by grep (Monsignor) on May 13, 2002 at 05:06 UTC | |
by slok (Acolyte) on May 13, 2002 at 06:09 UTC | |
by grep (Monsignor) on May 13, 2002 at 07:01 UTC | |
by slok (Acolyte) on May 15, 2002 at 11:30 UTC | |
by chromatic (Archbishop) on May 15, 2002 at 14:39 UTC | |
|
Re: CGI or DBI 'cache' problem
by grep (Monsignor) on May 13, 2002 at 03:45 UTC | |
|
Re: CGI or DBI 'cache' problem
by tjh (Curate) on May 13, 2002 at 13:26 UTC |