Gossamer Forum
Home : Products : DBMan SQL : Discussion :

External Perl Script for reading records from a table

Quote Reply
External Perl Script for reading records from a table
I am trying to write an external Perl script to print latest 10 records from a database table. This script will log into the DBMan SQL database, query for latest 10 records and print them.

For the earlier version of DBMan SQL, following script worked well.

#!/usr/local/bin/perl

require DBI;


# Connect to the database.
my $dbh = DBI->connect('DBI:mysql:mydb', 'myuserid','mypassword', {RaiseError => 1});
# This query will select the info we want.
my $query = qq!SELECT item, price, quantity, category, description, color
FROM Sample!;

# Prepare the query.
my $sth = $dbh->prepare($query);
# Execute it.
$sth->execute();

# Get the results.
my ( $item, $price, $quantity, $category, $description, $color, $picture );
( $item, $price, $quantity, $category, $description, $color, $picture) = $sth->fetchrow_array;

# Print records---------
print OUT "Price: $price";
print OUT " Quantity $quantity";
print OUT " Category: $category End\n";
print OUT " Description: $description End\n";

# Clean up
$sth->finish();
# Disconnect
$DBH->disconnect();


Need to adapt the above script to the latest version. Has anyone done a similar external script that logs in and reads? Would appreciate any help in making this work.

Thanks.

TIF

Subject Author Views Date
Thread External Perl Script for reading records from a table TIF 3663 Nov 27, 2005, 8:23 PM
Thread Re: [TIF] External Perl Script for reading records from a table
tandat 3560 Nov 29, 2005, 4:55 AM
Post Re: [tandat] External Perl Script for reading records from a table
TIF 3538 Dec 2, 2005, 7:07 AM