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
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