in reply to DBI placeholders
Here's a slight revision of what you have written. It has several benefits:
- strict: misspelling variable names can be a bummer.
- DBI->trace. Read the DBI documentation. This is a great debugging tool.
- RaiseError is set in the connect string. You no longer need to test every single DBI statement.
- Took out use DBD::Oracle; DBI will load the correct DBD for you :)
use strict; use DBI; # Define sid, user, password, etc. here my ( $host, $sid, $user, $passwd ) = some_func(); my $dbh = DBI->connect( "dbi:Oracle:host=$host;sid=$sid", $user, $p +asswd, { RaiseError => 1, AutoCommit => 0 } ) or die DBI->errstr; DBI->trace( 2, 'dbi_trace.txt' ); my $name = "guppy"; my $sql_statement = 'SELECT foo FROM table_bar WHERE name = ?'; my $sth = $dbh->prepare( $sql_statement ); # This is where I try to replace the placeholder with $name $sth->execute( $name ); while( my $aref = $sth->fetchrow_arrayref ) { print $aref->[0] ."\n"; } $sth->finish; $dbh->commit; $dbh->disconnect;
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In Section
Seekers of Perl Wisdom