Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.

In reply to (Ovid) Re: DBI placeholders by Ovid
in thread DBI placeholders by randomblue

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2022-12-08 10:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found