Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems getting MS Access info to print with DBI:ODBC

Status
Not open for further replies.

rmayer4

Programmer
Oct 2, 2001
9
CA
hey hey!
I keep getting this error when I try to print the results of my database query:

[tt]Global symbol "$row" requires explicit package name at script1.pl line 13.
Global symbol "$row" requires explicit package name at script1.pl line 14.
Global symbol "$row" requires explicit package name at script1.pl line 15.
Global symbol "$row" requires explicit package name at script1.pl line 15.
Execution of script1.pl aborted due to compilation errors.[/tt]

It's just a simple script, but I'm a newbie, so I really don't know what the problem is, I've been working on it for a while... Here the code:

Code:
#!C:/perl/bin/perl -w

use DBI; 
use strict; 
my $database = "dmhc01"; 
my $data_source = "DBI:ODBC:$database"; 
my $dbh = DBI->connect($data_source) 
or die "Can't connect to $data_source";
my $sth = $dbh->prepare("select id, age from invent4 where ctn like '%weymouth%'")
or die "Can't prepare sql statement";
$sth->execute ||
 die "Could not execute SQL statement";
$row = $sth->fetchrow_hashref;
while ($row=$sth->fetchrow_hashref)
	 {print "id: $row->{id}\t
	         age: $row->{age}\n"}
exit(0);


I'm using ActivePerl perl, v 5.6.1 built for MSWin32-x86-multi-thread, Binary build 630,
DBI 1.20
DBD:ODBC 0.28
Apache 1.3.20 (Win32)
MS Access 2000 (9.0.3821) SR-1


I've looked around, and can't find a FAQ or thread or anything to help me, but if one exists, just point me in the right direction! Thanks!!

-Kasey
 

From a quick glance it looks like you need to close it with a paranthesis.

#!C:/perl/bin/perl -w

use DBI;
use strict;
my $database = "dmhc01";
my $data_source = "DBI:ODBC:$database";
my $dbh = DBI->connect($data_source)
or die "Can't connect to $data_source";
my $sth = $dbh->prepare("select id, age from
invent4 where ctn like '%weymouth%'")
or die "Can't prepare sql statement";
$sth->execute ||
die "Could not execute SQL statement";
$row = $sth->fetchrow_hashref;
while ($row=$sth->fetchrow_hashref)
{print "id: $row->{id}\t
age: $row->{age}\n"}
exit(0);
}
 
Thanks for the advice, but the {'s were already closed (see the green part below)... I kept playin for a bunch, and I started adding and removing "my's" at random, and I found when I added 'my' to $row=$sth->fetchrow_hashref everything worked fine...



Code:
#!C:/perl/bin/perl -w

use DBI; 
use strict; 
my $database = "dmhc01"; 
my $data_source = "DBI:ODBC:$database"; 
my $dbh = DBI->connect($data_source) 
or die "Can't connect to $data_source";
my $sth = $dbh->prepare("select id, age from invent4 where ctn like '%weymouth%'")
or die "Can't prepare sql statement";
$sth->execute ||
 die "Could not execute SQL statement";
my
Code:
 $row = $sth->fetchrow_hashref;
while ($row=$sth->fetchrow_hashref)
{
Code:
print "id: $row->{id}\t
             age: $row->{age}\n"
}
Code:
exit(0);

This seemed to work fine... I'll have to read up on this "my" statement deal, or package deal, or whatever it is, it seems to be a pretty powerful little word!

Thanks again! :cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top