Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

dbi style questions (code, discussion)

by deprecated (Priest)
on Dec 29, 2001 at 07:37 UTC ( [id://135057]=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $sth = $dbh -> prepare("insert into table1 (col1, col2, col2) value
    +s (?, ?, ?)");
    
  2. or download this
    # do we need an insert or an update?
    my $row_checker = $dbh -> prepare("select count(col1) from table1 wher
    +e col1 = ? and col2 = ? and
    ...
    my $inserter = $dbh -> prepare("insert into table1 (col1, col2, col2) 
    +values (?, ?, ?)");my $upda
    ter = $dbh -> parepare("update table1 set col1 = ?, col2 = ?, col3 = ?
    + where col1 = ? and col2 = 
    ? and col3 = ?");
    
  3. or download this
    my $row_checker = "select count(col1) from table1 where col1 = ? and c
    +ol2 = ? and col3 = ?";
    $row_checker = $dbh -> prepare($row_checker);
    ...
            update table1 set col1 = ?, col2 = ?, col3 = ?
                    where col1 = ? and col2 = ? and col3 = ?
    });
    
  4. or download this
    my $rowRef = $dbh -> selectrow_arrayref("select col1 from table1 where
    + col1 = col2 and col2 != '$
    someval'");
    ...
    my $tuple = shift @{ $rowRef };
    #or ...
    my $tuple = @{ $rowRef }[0];
    
  5. or download this
    my ($tuple) = map { @{ $_ } } $dbh -> selectall_arrayref("select col1 
    +from table1 where col1 = co
    l2 and col2 != '$someval'");
    
  6. or download this
    if ($tuple) { # succeeded...
    
  7. or download this
    my $next_col1 = "select distinct(col1) from table1";
    $next_col1 = $dbh -> prepare($next_col1);
    ...
    my @col1s = map { @{ $_ } } @{ $next_col1 -> fetchall_arrayref() };
    
    foreach my $col1 (@col1s) { ...
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://135057]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found