in reply to DBI and placeholders, see resulting query?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DBI and placeholders, see resulting query?
by Anonymous Monk on May 22, 2014 at 00:41 UTC | |
|
Re^2: DBI and placeholders, see resulting query?
by erix (Prior) on Jun 06, 2014 at 08:58 UTC | |
by mje (Curate) on Jun 06, 2014 at 09:35 UTC |