in reply to Re^3: DBD::CSV - missing first row?
in thread DBD::CSV - missing first row?
#!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;"); my $content = ''; open (FILE,"c:/apache/htdocs/test2.csv") || die "unable to open file"; while (<FILE>) { print $_; } close(FILE); # Associate our csv file with the table name 'test2' $dbh->{'csv_tables'}->{'test2'} = { 'file' => 'c:/apache/htdocs/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();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: DBD::CSV - missing first row?
by holli (Abbot) on May 08, 2005 at 07:38 UTC |