$sth is your statement handle, and does not 
contain the results (rows) from your SELECT
sql statement. Consider this as a filehandle
if you like. 

You need one of the fetch routines to get the
rows that resulted from the SELECT sql statement.

There are several. This is an example I use:
while (@row=$sth->fetchrow_array()) {#fetch row and advance cursur 1 pos
  # process row data here
}
Also have a look at fetchrow_arrayref (returns a reference instead of
an array). And fetchrow_hashref. And I think there was another one.

As a good reference I would suggest getting a copy of O'Reilly's 
Programming the Perl DBI.

Hope this helps,

Hans Feringa





-------------------------------
email: [EMAIL PROTECTED] 
homepage: www.shelob.demon.nl
-------------------------------
The penguin rules!!
===============================

On Sun, 29 Apr 2001, Judge Dredd wrote:

> Hello there!
> 
> I have a database in access and I'm trying (with perl using DBI and
> DBD::ODBC in win32) to select specific fields from it and write them to a
> file. The script that I'm using is the one I'm providing below. The
> connection to the database works fine but I think there is a problem with
> the SELECT statement. The only thing that gets printed in the file is
> DBI::st=HASH(0x1914394) which is the only thing that I get as a response
> when the script runs. Essentially the problem is that I can not print the
> results of the query. Do you have any ideas on this? Any help would be 
> much appreciated.
> 
> For those in multiple lists sorry for the cross-post
> 
> Thanks in advance.
> 
> #!perl
> 
> use DBI;
> use strict;
> 
> my $DSN = 'driver=Microsoft Access Driver (*.mdb);
> dbq=\\\\server\\path\\to\\database\\db1.mdb';
> my $dbh = DBI->connect("dbi:ODBC:$DSN") or die "$DBI::errstr\n";
> $dbh->{AutoCommit} = 1;$dbh->{RaiseError} = 1;
> 
>         my $sth = $dbh->prepare(q{
>         SELECT (DNS_id, help) FROM DNS}) || die $dbh->errstr;
>         chop;
>         $sth->execute() || die $dbh->errstr;
> 
> unless (open(ZONEFILE2, ">zonefile2")){
>         die ("Missing File");
> }
> 
> print ZONEFILE2 "$sth";
> close(ZONEFILE2);
> 
> $sth->finish;
> $dbh->disconnect;
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> _______________________________________________
> Perl-Win32-Database mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/perl-win32-database
> 

Reply via email to