By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,848 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,848 IT Pros & Developers. It's quick & easy.

use DBI; package problem

P: 36
Hello,
I have one perl code.
'
Here they are using oracle database. To extract that data from database they are using DBI module.

in this program they have used some queries also.
i have such proram here here
in query they have used

? ? ? but i do not know what is this questions maks.
please can any one exaplain me the usage of this question mark inside the query.

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use DBI qw(:sql_types);
  3.  
  4. my $dbh = DBI->connect( 'dbi:Oracle:orcl',
  5.                         'jeffrey',
  6.                         'jeffspassword',
  7.                         {
  8.                           RaiseError => 1,
  9.                           AutoCommit => 0
  10.                         }
  11.                       ) || die "Database connection not made: $DBI::errstr";
  12.  
  13. my @records = (
  14.                 [ 0, "Larry Wall",      "Perl Author",  "555-0101" ],
  15.                 [ 1, "Tim Bunce",       "DBI Author",   "555-0202" ],
  16.                 [ 2, "Randal Schwartz", "Guy at Large", "555-0303" ],
  17.                 [ 3, "Doug MacEachern", "Apache Man",   "555-0404" ] 
  18.               );
  19.  
  20. my $sql = qq{ INSERT INTO employees VALUES ( ?, ?, ?, ? ) };my $sth = $dbh->prepare( $sql );
  21.  
  22.  
  23. for( @records ) {
  24.   eval {
  25.     $sth->bind_param( 1, @$_->[0], SQL_INTEGER );
  26.     $sth->bind_param( 2, @$_->[1], SQL_VARCHAR );
  27.     $sth->bind_param( 3, @$_->[2], SQL_VARCHAR );
  28.     $sth->bind_param( 4, @$_->[3], SQL_VARCHAR );
  29.     $sth->execute();
  30.     $dbh->commit();
  31.   };
  32.  
  33.   if( $@ ) {
  34.     warn "Database error: $DBI::errstr\n";
  35.     $dbh->rollback(); #just die if rollback is failing
  36.   }
  37. }
  38.  
  39. $sth->finish();
  40. $dbh->disconnect();

shafi
Jan 24 '08 #1
Share this Question
Share on Google+
1 Reply


eWish
Expert 100+
P: 971
The ?'s when used with the DBI are called Placeholders. Read the documentation for more.

--Kevin
Jan 24 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.