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

Quote Reply
Re: [TIF] External Perl Script for reading records from a table In reply to
Hi TIF,

That can be done by creating a global. We can save a lot of stuff of sql by using the built-in $DB object.

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] External Perl Script for reading records from a table In reply to
Dat,

Thanks for your help. I was able to do it.

TIF