Apologies for posting a small script. I created a little test table
with columns testname, testsex, testage and testcolour. The script
runs without errors yet the value of returned rows is always zero.
Please would someone be so kind as to point out the error of my ways.
TIA
Francesco
#!/usr/bin/perl -w
#
# test script to query an mysql database
#
use strict;
use DBI;
my ( $dbh, $value1, $value2, $sth, @rows, $counter, $field_name, $field2, $field1);
print "Enter the first fieldname (field1) : "; chomp ($field1 = <>);
print "Enter the second fieldname (field2) : "; chomp ($field2 = <>);
print "enter the value for field one : "; chomp ($value1 = <>);
print "enter the value for field two : "; chomp ($value2 = <>);
$dbh = DBI -> connect ("DBI:mysql:ami","fgs") || die $DBI::errstr;
$sth = $dbh -> prepare( qq{
select * from testami where \"\$field1\" = \"$value1\" and \"\$field2\" =
\"\$value2\"
});
$sth -> execute();
$counter = "0";
while ( @rows = $sth -> fetchrow_array ()) {
$counter++;
print "@rows\n";
}
print "Number of records = $counter\n\n";
$dbh -> disconnect;