I'm working in a Perl script and I'd like to use named parameters to perform a query in a Postgres database. The DBI documentation says that's not portable:
Some drivers also allow placeholders like :name and :N (e.g., :1, :2, and so on) in addition to ?, but their use is not portable
I'd like to do that anyway. Does anyone know if the Postgres driver implement that?
Instead of performing a query like this:
$q = $pg->prepare($query);
$q->bind_param(1, "value");
$q->bind_param(2, "value");
$q->execute();
I'd like to do something like this:
$q = $pg->prepare($query);
$q->bind_param("parameterX", "value");
$q->bind_param("parameterY", "value");
$q->execute();
Cheers!
EDIT
The correct syntax is as follows (I was missing the colon):
$q = $pg->prepare($query);
$q->bind_param(":parameterX", "value");
$q->bind_param(":parameterY", "value");
$q->execute();
It is supported, but discouraged:
The final placeholder type is "named parameters" in the format ":foo". While this syntax is supported by DBD::Pg, its use is discouraged in favor of dollar-sign numbers.
The different types of placeholders cannot be mixed within a statement, but you may use different ones for each statement handle you have. This is confusing at best, so stick to one style within your program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With