http://www.perlmonks.org?node_id=927185


in reply to Fetch Data from MySQL

Here is your basic example, setting up and populating the test data table is up to you. You must have DBI and DBD::Mysql installed. DBI will find all installed sql drivers automatically
#!/usr/bin/perl use warnings; use strict; use DBI; # Gather some information from the user : print "Enter your MySQL username: "; my $username = <STDIN>; chomp $username; # remove trailing newline from Enter keypress print "Enter your MySQL password; "; my $password = <STDIN>; chomp $password; # Connect to the database my $dbh = DBI->connect("DBI:mysql:database=perl:host=localhost",$usern +ame,$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;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh