I have this inside of a for loop, but the sql itself should be the same, with only the variables changing. So I thought, well I can just move that getValueByMeaning() function as a parameter (like the download_id and update_time) and set the $sql_ins_log outside of the for loop to avoid setting the variable over and over to the same thing, like this:my $sql_ins_log = "insert into download_log (download_id,status,update +_time)" . " values(?,getValueByMeaning('$status_meaning','17') +,?)";
I tried a variety of things, but I'm having issues that I think relates to the fact that it's a function and there's a variable in it (meaning, it's not just a function like NOW()). To be clear, the getValueByMeaning is a user defined MySQL function, not a Perl function in this script. So I want the actual SQL to get passed into MySQL like this:my $sql_ins_log = "insert into download_log (download_id,status,update +_time)" . " values(?,?,?)"; foreach(@X){ $now = localtime->mysql_datetime; $sth = $dbh->prepare($sql_ins_log); $sth->execute($download_id,getValueByMeaning('$status_meaning','17') +,$now); }
Thanks for ay insight!insert into download_log (download_id,status,update_time) values(1,get +ValueByMeaning('DONE',17'),'2014-09-15 14:16:00')
In reply to MySQL Parameterized Query with Functions by hoyt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |