MySQL Forums
Forum List  »  Perl

Re: Trouble with parameters and IN query
Posted by: Randy Clamons
Date: October 30, 2007 12:21PM

The problem you're seeing is most likely in the way you are passing the parameter as a single value and attempting to have it read as two values. mySql will convert the data type to something that makes sense to it. So, when you bind '2,3' to the single question mark, it sees the comma and interprets it as a string.

Here's a suggestion. It looks like you can get one or more comma-separated values in $user_supplied_value. Try something like this:
@user_supplied_values = split /,/, $user_supplied_value;
$params = '';

for (@user_supplied_values) {
     # make one question mark for each value
     $params .= ($params?',':'').'?'
}
# Now prepare your statement
$sth = $dbh->prepare(qq( select * from ip where id in ($params) ));

for ($i=0; $i<@user_supplied_values; i++) {
     # Now bind your parameters
     $sth->bind_param($i+1, $user_supplied_values[$i], { TYPE => 'SQL_INTEGER' }); 
}

# You should be ready to go now!
$sth->execute() or print $sth->errstr, "<br>\n";

Options: ReplyQuote


Subject
Written By
Posted
Re: Trouble with parameters and IN query
October 30, 2007 12:21PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.