#!/usr/bin/perl use warnings; use strict; use DBI; # Gather some information from the user : print "Enter your MySQL username: "; my $username = ; chomp $username; # remove trailing newline from Enter keypress print "Enter your MySQL password; "; my $password = ; chomp $password; # Connect to the database my $dbh = DBI->connect("DBI:mysql:database=perl:host=localhost",$username,$password) || die "Couldn't connect to database"; print "Database connection established."; # Prepare statement my $sth = $dbh->prepare( "SELECT * FROM perl_table" ); # Send statement to database $sth->execute || die "Couldn't execute statement"; # Print out the data my @row; while ( @row = $sth->fetchrow_array() ) { print "@row \n"; } # One more thing: we need to disconnect from the database server # when we're done. $dbh->disconnect;