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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fail extractng DB data with DBI module

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
HI,

The following sub extracts data nicely from all tables,just one table comes up empty.
Will appreciate ideas on possible issues in the code.
thanks
=======================
sub exportMDB {
my $database = shift;
my $driver = "Microsoft Access Driver (*.mdb)";
print "$database\n";
print "---------------------------------\n\n";
my $dsn = "dbi:ODBC:driver=$driver;dbq=$database";
my $dbh = DBI->connect("$dsn") or warn "Couldn't open database: $DBI::errstr; stopped";

my $sth = $dbh->table_info( "", "", "", "TABLE" );

while ( my ($catalog, $schema, $table, $type) = $sth->fetchrow_array() ) {
if ($table) {
print "\n$table :\n";
print "--------\n";
my $sql = "select * from $table";

# Prepare the SQL query for execution
my $sth = $dbh->prepare($sql) or warn "Couldn't prepare statement:$DBI::errstr; stopped";

# Execute the query
$sth->execute() or warn "Couldn't execute statement: $DBI::errstr; stopped";

# Fetch each row and print it
while ( my (@row) = $sth->fetchrow_array() ) {
print "$_\t" foreach (@row);
print "\n";
}
}
}
$dbh->disconnect(); # Disconnect from the database
}

Long live king Moshiach !
 
Hi,
Is the table being queried or not being queried?

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Hi,
Not sure but try
Code:
my $sth = $dbh->table_info( "", "", "", "%" );

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top