Bod has asked for the wisdom of the Perl Monks concerning the following question:
Thanks to the wisdom of The Monastery I have started using placeholders for all database operations and they are being retro applied to existing code whenever I look at it to enhance security.
In a number of places I have wanted to use the same placeholder multiple times. I have found reference to named placeholders but cannot find a working example and the few experiments I have tried have not worked. Here is an example from production code:
Here all four placeholders are the same. I have tried using bind_param but that doesn't workmy $query = $dbh->prepare("SELECT idOutbound, type, DAY(dateDue) FROM +LD_Outbound WHERE (dateDue >= ? AND dateDue < ? + INTERVAL 1 MONTH) O +R (defaultDate >= ? AND defaultDate < ? + INTERVAL 1 MONTH)"); $query->execute("$last_y-$last_m-01", "$last_y-$last_m-01", "$last_y-$ +last_m-01", "$last_y-$last_m-01");
The documentation is not very clear.my $query = $dbh->prepare("SELECT idOutbound, type, DAY(dateDue) FROM +LD_Outbound WHERE (dateDue >= ?:NOW AND dateDue < ?:NOW + INTERVAL 1 +MONTH) OR (defaultDate >= ?:NOW AND defaultDate < ?:NOW + INTERVAL 1 +MONTH)"); $query->bind_param(:NOW, "$last_y-$last_m-01"); $query->execute();
Is there a way to just specify the variable once if it is going to be used multiple times in the query?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reusing placeholders
by hippo (Archbishop) on Mar 27, 2021 at 12:58 UTC | |
by Bod (Parson) on Mar 27, 2021 at 23:20 UTC | |
|
Re: Reusing placeholders
by erix (Prior) on Mar 27, 2021 at 13:56 UTC | |
by Bod (Parson) on Mar 27, 2021 at 23:26 UTC | |
|
Re: Reusing placeholders
by LanX (Saint) on Mar 27, 2021 at 15:08 UTC | |
by Bod (Parson) on Mar 27, 2021 at 23:17 UTC | |
by LanX (Saint) on Mar 28, 2021 at 00:10 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |