Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

(Ovid) Re: DBI placeholders

by Ovid (Cardinal)
on Nov 02, 2001 at 03:58 UTC ( #122723=note: print w/replies, xml ) Need Help??

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;


Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://122723]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2022-11-29 01:52 GMT
Find Nodes?
    Voting Booth?