Hi all,
I'm currently having to modify PERL scripts created by an ex-coworker. I'm unfamiliar with DBI and could use a little help if anyone is so inclined.
The problem I'm having is that he's using bind_parameter in the scripts to substitute placeholders in the SQL with command line arguments, and I'd like to change a statement's WHERE clause from "id = ?" to "id in (?)" to allow a range of possible values to be input from the command line.
When the statement I'd expect to result from the bind_paramater statement, "SELECT id from sport where id IN (7,8)" is executed from the MySQL monitor, MySQL returns the correct two values:
When the PERL code above executes, though, PERL returns only one result:
So... I guess my question is less how to use bind_param to subsitute a series of values into an IN clause, and more how I can view the literal result of the bind_parameter statement, but an answer to either would be tremendously helpful.
In other words, I'd really like to be able to see the resultant SQL that's created after the parameters are bound to help in debugging this kind of stuff in general.
Anyone have any suggestions?
Thanks in advance,
Chuck
I'm currently having to modify PERL scripts created by an ex-coworker. I'm unfamiliar with DBI and could use a little help if anyone is so inclined.
The problem I'm having is that he's using bind_parameter in the scripts to substitute placeholders in the SQL with command line arguments, and I'd like to change a statement's WHERE clause from "id = ?" to "id in (?)" to allow a range of possible values to be input from the command line.
Code:
#!/opt/csw/bin/perl
# Script Name: test
use DBI;
$dbh = DBI->connect('DBI:mysql:databasename', password);
$query = "SELECT description from sport where id IN (?)";
$table_event_list = $dbh->prepare("$query");
$sports = "7,8";
$rv = $table_event_list->bind_param(1,$sports);
# Execute the query
$table_event_list->execute;
# Loop through the list of sport ID's
while( @row = $table_event_list->fetchrow_array() ) {
print "SPORT:" . $row[0] . "\n";
}
$table_event_list->finish;
When the statement I'd expect to result from the bind_paramater statement, "SELECT id from sport where id IN (7,8)" is executed from the MySQL monitor, MySQL returns the correct two values:
Code:
mysql> select description from sport where id in (7,8);
+------------------+
| description |
+------------------+
| Girls Basketball |
| Boys Soccer |
+------------------+
2 rows in set (0.00 sec)
Code:
# ./test
SPORT:Girls Basketball
#
So... I guess my question is less how to use bind_param to subsitute a series of values into an IN clause, and more how I can view the literal result of the bind_parameter statement, but an answer to either would be tremendously helpful.
In other words, I'd really like to be able to see the resultant SQL that's created after the parameters are bound to help in debugging this kind of stuff in general.
Anyone have any suggestions?
Thanks in advance,
Chuck