in reply to select from mysql table based on two column match
#!/usr/bin/perl -w use strict; use warnings; use DBI; #Get first input print "Enter cpt code> "; my $cptcode = <STDIN>; #Get Second input print "Enter cpt2 code> "; my $cpt2code = <STDIN>; if ( ($cptcode != “”) && ($cpt2code != “”)) { 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 column1 = +$cptcode AND column2 = $cpt2code’) or die "Couldn't prepare statement: " . $dbh->errstr; $sth->execute() # Execute the query or die "Couldn't execute statement: " . $sth->errstr; # Read the matching records and print them out while (my @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; $dbh->disconnect; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: select from mysql table based on two column match
by marto (Cardinal) on Jan 24, 2017 at 10:54 UTC | |
by afoken (Chancellor) on Jan 26, 2017 at 20:15 UTC | |
|
Re^2: select from mysql table based on two column match
by haukex (Archbishop) on Jan 24, 2017 at 10:54 UTC | |
|
Re^2: select from mysql table based on two column match
by abner (Novice) on Jan 24, 2017 at 18:50 UTC | |
by Anonymous Monk on Jan 25, 2017 at 06:18 UTC |