加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

使用名称将参数绑定到Perl中的postgres查询

发布时间:2020-12-16 06:16:55 所属栏目:大数据 来源:网络整理
导读:我正在使用Perl脚本,我想使用命名参数在Postgres数据库中执行查询. DBI documentation说这不便携: 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 无论如何我还想那样做.
我正在使用Perl脚本,我想使用命名参数在Postgres数据库中执行查询. DBI documentation说这不便携:

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

无论如何我还想那样做.有谁知道Postgres驱动程序是否实现了这一点?

而不是执行这样的查询:

$q = $pg->prepare($query);
 $q->bind_param(1,"value");
 $q->bind_param(2,"value");
 $q->execute();

我想做这样的事情:

$q = $pg->prepare($query);
 $q->bind_param("parameterX","value");
 $q->bind_param("parameterY","value");
 $q->execute();

干杯!

编辑

正确的语法如下(我错过了冒号):

$q = $pg->prepare($query);
 $q->bind_param(":parameterX","value");
 $q->bind_param(":parameterY","value");
 $q->execute();

解决方法

It is supported,但气馁:

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读