Hi Everybody,

I have been programming with Perl for over four years, but I've never had
a whole lot of reason to work with DBI or even databases very much for
that matter.

I'm currently working on a very simple set of scripts to read data from a
couple different Postgres tables and parse the data in different ways.  I
wanted to start off by simply printing some data (as I did not create the
tables and want to see what the data actually looks like).  Below is the
code I am using to do that.  The error message I am getting is
"DBD::Pg::st fetchrow_array failed: no state at query.pl line 14."  I've
gone through all the books I have, the DBI documentation and the DBD::Pg
documentation, but I can't seem to figure out what could be causing the
problem.  As far as I can tell, what I'm doing looks like every other
example I've seen.

If anyone can point me in the right direction on this I'd really
appreciate it.

Here's the code:

#!/usr/bin/perl -w
use strict;
use DBI;

my $username="nobody";
my $password="";
my $db="DBI:Pg:dbname='catalog';";
my $dbh=DBI->connect($db, ,$username,$password)
        or die "Couldn't connect".DBI->errstr;
my $sth=$dbh->prepare('SELECT * FROM tbl_clients')
        or die "Couldn't prepare statement: " . $dbh;

my @data;
while(@data=$sth->fetchrow_array()) { ##  The offending line
        my $clientid=$data[1];
        my $clientname=$data[2];
        print "NAME:  $clientname\nID:  $clientid\n\n";
}
$sth->finish;
$dbh->disconnect;

Thanks in advance!

-Dave

--

David Rankin
Tel:  401.277.9966/877.528.5213
Fax:  603.590.4925
Email:  [EMAIL PROTECTED]
http://www.surfthisdesign.com


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to