#!/usr/bin/perl -w # first experiments in perl front end for mysql queries use strict; use warnings; use DBI; my $dbh = DBI->connect('dbi:mysql:mydatabase:localhost:3306','abc','xyz') or die "Couldn't connect to database: " . DBI->errstr; my $sth = $dbh->prepare('SELECT * FROM charge WHERE cpt = ?') or die "Couldn't prepare statement: " . $dbh->errstr; print "Enter cpt code> "; while (my $cptcode = <>) { # Read input from the user my @data; chomp $cptcode; exit 0 if ($cptcode eq ""); $sth->execute($cptcode) # Execute the query or die "Couldn't execute statement: " . $sth->errstr; # Read the matching records and print them out while (@data = $sth->fetchrow_array()) { my $cptanswer = $data[1]; my $insid = $data[2]; my $preauth = $data[3]; my $updated = $data[5]; print "\t$cptanswer\t$insid\t$preauth\t$updated\n"; } if ($sth->rows == 0) { print "No names matched `$cptcode'.\n\n"; } $sth->finish; print "\n"; print "Enter cpt code> "; } $dbh->disconnect;