Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unexpected query result 2

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
The following code set $rv1 to a value of -2 on an empty table yet works ok on a populated table.
Code:
my $sql1="SELECT OU, OP, QU, QP, FNUM, MESSIGE, RED, FREDNO, QNUM from BABBLE WHERE OU=\"$MET\ AND OP=\"$YUT\"";
my $sth1=$dbh->prepare($sql1);
$sth1->execute();
my $rv1=$sth1->rows;
I can work round it but is there an underlying cause?

Keith
 
my $sql1="SELECT OU, OP, QU, QP, FNUM, MESSIGE, RED, FREDNO, QNUM from BABBLE WHERE OU=\"$MET\ AND OP=\"$YUT\"";


I dont see an ending double qoute.
OU=\"$MET\(") ??

and shouldnt u be using single quotes instead of double ?

 
If you're using a prepared statement, you should also be using placeholders for the parameters. That way, DBI takes care of all your quoting for you:
Code:
my $sql1="SELECT OU, OP, QU, QP, FNUM, MESSIGE, RED, FREDNO, QNUM from BABBLE WHERE OU=? AND OP=?";
my $sth1=$dbh->prepare($sql1);
$sth1->execute( $MET, $YUT );
my $rv1=$sth1->rows;
 
Thanks very much for that.
I need some new eyes I think!

Thanks for the tip about the quotes, I am in the habit of using delimited doubles.

Will this cause problems?



Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top