#!/usr/bin/perl

use DBI;

$database='mysql_database';
$hostname='server.domain.com';
$port='3306';
$user='user';
$password='passwd';

# Step 1: Prepare 
  print "Preparing statement\n";
  $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
  $dbh =  DBI->connect($dsn, $user, $password, { RaiseError => 1 })
          or die "Can't make 1st database connect: $DBI::errstr\n";
  $sth1 = $dbh->prepare ( "
             select 
	     	*
	     from 
	     	db
	     " );

# Setp 2: Execute
  print "Executing statement\n";
  $sth1->execute(  )
     or die("Something failed:\t$!\n");

## Setp 3: Fetch
  print "Fetch statements\n";
  #########################################
  # Fetch the row references and stash 'em!
  my @stash;
  while ( $array_ref = $sth1->fetchrow_arrayref ) {
    push @stash, [ @$array_ref ];  # Copy the array contents
  }
  # Dump the stash contents!
  print "Dump statement\n";
  foreach $array_ref ( @stash ) {
    print "Row: @$array_ref\n";
  }
  #########################################
  

# Setp 4: Deallocation
  print "Deallocation statement\n";
  $dbh->disconnect
    or warn "Disconnection failed: $DBI::errstr\n";

exit;

