http://www.perlmonks.org?node_id=122723


in reply to DBI placeholders

Here's a slight revision of what you have written. It has several benefits:

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.