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');