> I was looking at the example code in the mysql examples directory. They seem > to have been created for testing things like very large records. > > Does anyone have a minimal example that executes a SQL SELECT command and > displays the results? > > I need something really simple to get me started. > > It's not a big deal, I could probably figure it out from the examples in the > mysql installation. They are just a bit more convoluted than necessary. I > just thought that if someone had a simple sample lying around it would save > me some time. > > Thanks, > Siegfried > >
#!/usr/bin/perl use strict; use warnings; use DBI ; use Data::Dumper; our $dbh; sub DBH { unless ( $dbh && $dbh->ping ) { $dbh = DBI->connect ( 'dbi:mysql:dbname=fuzzy', 'alrwneec', 'top-secret-password-dont-tell-anyone' ) ; die DBI->errstr unless $dbh && $dbh->ping; } return $dbh; } my $sth = DBH->prepare ( q { SELECT city, population FROM city WHERE population > 50000 } ); die "No sth: " . DBH->errstr unless $sth; $sth->execute || die "no select: " $sth->errstr; while ( my $row = $sth->fetch ) { my ($city, $population) = @$row; print "$city has a population of $population \n"; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>