Skip to content

Instantly share code, notes, and snippets.

@seratch
Created August 5, 2008 17:08
Show Gist options
  • Save seratch/4099 to your computer and use it in GitHub Desktop.
Save seratch/4099 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Data::Dumper;
my $rdbms = 'mysql';
my $db = 'database_name';
my $host = 'host_name';
my $ds = 'DBI:'.$rdbms.':'.$db.':'.$host;
my $user = 'user_name';
my $pass = 'password';
my $dbh = DBI->connect($ds, $user, $pass,{RaiseError=>0,PrintError=>1,AutoCommit=>1})
|| die "Got error $DBI::errstr when connecting to $ds\n";
my $table = 'some_table';
my $sth = $dbh->prepare("select * from $table;");
my $res = $sth->execute;
while(my $ref = $sth->fetchrow_hashref){
print Data::Dumper::Dumper($ref);
}
$dbh->disconnect;
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment