Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

The fine art of database programming

by gmax (Abbot)
on Apr 29, 2002 at 05:17 UTC ( #162771=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $dbh = DBI->connect($DNS, {RaiseError=>1});
    my $sth = $dbh->prepare(qq{SELECT product, price, quantity 
    ...
        ask_customer ($product, $price, $quantity);
    }
    $dbh->disconnect();
    
  2. or download this
    +----------------------+   +-----------------------+
    |       customer       |   |          order        |
    ...
    | P03 | 5.50  | pliers |
    | P04 | 4.00  | cutter |
    +-----+-------+--------+
    
  3. or download this
    my @customers = (
        [ 'C01', 'Joe',   'NY' ],
    ...
       [ 'C01', 'P04',   4 ],
       [ 'C01', 'P03',   1 ]
     );
    
  4. or download this
    SELECT cust.name AS customer, prod.name AS product,
    price, qty, qty*price AS total
    ...
    | Sue      | 28.20 |
    | Joe      | 25.50 |
    +----------+-------+
    
  5. or download this
    my %orders_by_customer = (
    'Frank' => [ { product => 'pliers',  qty =>   9 },
    ...
                 { product => 'pliers',  qty =>   1 }
               ] 
    );
    
  6. or download this
    my %orders_by_customer = ();
    while (my $href = $sth->fetchrow_hashref()) {
    ...
       );
       push @{$orders_by_customer{$href->{'customer'}}}, \%order;
    }
    
  7. or download this
     
        my $surname = 'Jones';
        my $query= 
            qq{SELECT name, surname FROM employees WHERE surname = $surnam
    +e };
        my $sth = $dbh->prepare($query);
        $sth->execute();
    
  8. or download this
     
        my $query= qq{SELECT name, surname FROM employees WHERE surname = 
    +? };
        my $sth = $dbh->prepare($query);
        $sth->execute('Jones');
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://162771]
Approved by rob_au
Front-paged by jeffa
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-12-20 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (97 votes), past polls