Assuming customer_dbi.pl:

#!/opt/perl-5.20/bin/perl use strict; use warnings; use DBI; main(); exit; sub main { my $dbh = DBI->connect or die "oops - $!\n"; my $Customer_ID = 10; my $sql = "select customer_id from t where customer_id = ?"; my $sth = $dbh->prepare($sql) or die "oops - $!\n"; my $rc = $sth->execute($Customer_ID); while (my $rrow = $sth->fetch) { print $rrow->[0], "\n"; } }

You can call it with DBI_TRACE either on or off:

$ DBI_TRACE=0 ./customer_dbi.pl 10 $ DBI_TRACE=1 ./customer_dbi.pl DBI 1.628-nothread default trace level set to 0x0/1 (pid 5340 pi 0 +) at DBI.pm line 287 via customer_dbi.pl line 4 -> DBI->connect(, , ****) -> DBI->install_driver(Pg) for linux perl=5.020000 pid=5340 ruid=5 +00 euid=500 install_driver: DBD::Pg version 2.19.3 loaded from /home/aardva +rk/perl-5.20/lib/site_perl/5.20.0/x86_64-linux/DBD/Pg.pm <- install_driver= DBI::dr=HASH(0xd1ad40) !! warn: 0 CLEARED by call to default_user method <- default_user(undef, undef, ...)= ( undef undef ) [2 items] at D +BI.pm line 657 <- connect('', undef, ...)= ( DBI::db=HASH(0xfd4258) ) [1 items] a +t DBI.pm line 669 <- STORE('PrintError', 1)= ( 1 ) [1 items] at DBI.pm line 721 <- STORE('AutoCommit', 1)= ( 1 ) [1 items] at DBI.pm line 721 <- STORE('Username', undef)= ( 1 ) [1 items] at DBI.pm line 724 <- connected= ( undef ) [1 items] at DBI.pm line 731 <- connect= DBI::db=HASH(0xfd4258) <- STORE('dbi_connect_closure', CODE(0xfd3c58))= ( 1 ) [1 items] a +t DBI.pm line 740 <- prepare('select * from t where customer_id = ?')= ( DBI::st=HAS +H(0xfd4588) ) [1 items] at customer_dbi.pl line 12 <- execute(10)= ( 1 ) [1 items] at customer_dbi.pl line 13 <- fetch= ( [ 10 ] ) [1 items] row1 at customer_dbi.pl line 14 10 <- fetch= ( undef ) [1 items] row1 at customer_dbi.pl line 14 <- DESTROY(DBI::st=HASH(0xfd4348))= ( undef ) [1 items] at custome +r_dbi.pl line 5 <- DESTROY(DBI::db=HASH(0xfd4198))= ( undef ) [1 items] at custome +r_dbi.pl line 5 <- disconnect_all= ( '' ) [1 items] at DBI.pm line 748 ! <- DESTROY(DBI::dr=HASH(0xd1ad40))= ( undef ) [1 items] during glo +bal destruction

In reply to Re: DBI and placeholders, see resulting query? by erix
in thread DBI and placeholders, see resulting query? by DreamT

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.