#!c:/apache/perl/bin/perl.exe -wT BEGIN { $| = 1; open (STDERR, ">&STDOUT"); print qq~Content-type: text/html\n\n~; } use CGI qw/:standard/; use strict; use Data::Dumper; use DBI; my $foo = new CGI; print $foo->header; # Connect to the database, (the directory containing our csv file(s)) my $dbh = DBI->connect("DBI:CSV:f_dir=.;csv_eol=\n;"); # Associate our csv file with the table name 'test2' $dbh->{'csv_tables'}->{'test2'} = { 'file' => 'test2.csv'}; # Output the name and contact field from each row my $sth = $dbh->prepare("SELECT * FROM test2 WHERE name LIKE 'G%'"); $sth->execute() or die "Can't execute the query: $sth->errstr"; while (my $row = $sth->fetchrow_hashref) { print("name = ", $row->{'Name'}, " contact = ", $row->{'Contact'}. "\n"); } $sth->finish(); #### "Name","Address","Floors","Donated last year","Contact" "Charlotte French Cakes","1179 Glenhuntly Rd",1,"Y","John" "Glenhuntly Pharmacy","1181 Glenhuntly Rd",1,"Y","Paul" "Dick Wicks Magnetic Pain Relief","1183-1185 Glenhuntly Rd",1,"Y","George" "Gilmour's Shoes","1187 Glenhuntly Rd",1,"Y","Ringo" #### Content-Type: text/html; charset=ISO-8859-1 Execution ERROR: Missing first row at c:/apache/Perl/site/lib/DBD/CSV.pm line 165, line 1. . DBD::CSV::st fetchrow_hashref failed: Attempt to fetch row from a Non-SELECT statement [for statement ``SELECT * FROM test2 WHERE name LIKE 'G%''']) at /apache/htdocs/test2.cgi line 26.