为什么我收到“无法调用方法“fetchrow_array”?没有包或对象引用”?

发布于 2024-09-29 10:04:19 字数 383 浏览 1 评论 0原文

我已经安装了 DBD::Pg 版本 2.17.1 但仍然出现使用以下代码时

$res = $conn->prepare($query);
$res = $res->execute();
@tuple = $res->fetchrow_array;

出错错误:

Can't call method "fetchrow_array" without a package or object reference at test.pl line 69.

请提出建议。

I have installed DBD::Pg version 2.17.1 but still still getting error while using below code

$res = $conn->prepare($query);
$res = $res->execute();
@tuple = $res->fetchrow_array;

error:

Can't call method "fetchrow_array" without a package or object reference at test.pl line 69.

Please suggest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦过后 2024-10-06 10:04:19

$res 不是 DBI 的对象实例。尝试运行 ref $res :它应该返回一个空字符串。

执行之前准备的
陈述。除了更新之外,
DELETE、INSERT 语句,其中
它总是返回的数量
受影响的行,执行方法可以
也可用于 SELECT ... INTO 表
声明。

您的 $res 很可能包含“受影响的行”的数量。

$sth   = $conn->prepare($query);
$nrows = $sth->execute();
@tuple = $sth->fetchrow_array;

$res is not an object instance of DBI. Try running ref $res: it should return an empty string.

Executes a previously prepared
statement. In addition to UPDATE,
DELETE, INSERT statements, for which
it returns always the number of
affected rows, the execute method can
also be used for SELECT ... INTO table
statements.

Your $res most likely contains the number of "affected rows".

$sth   = $conn->prepare($query);
$nrows = $sth->execute();
@tuple = $sth->fetchrow_array;
阿楠 2024-10-06 10:04:19

您不应该

$res = $res->execute();

在该语句之前说 $res 是执行成功后调用 fetchrow_array 所需的语句句柄,但上面将其替换为execute() 的返回值,即受影响的行数如果成功,则 undef 如果执行失败。相反,如果需要,可以将该返回值存储在单独的变量中,并在调用 fetchrow_array 之前检查它是否成功。

You should not be saying

$res = $res->execute();

$res before that statement is the statement handle that you will need to use to call fetchrow_array after the execute succeeds, but the above is replacing it with the return value of execute(), which is the number of rows affected if successful or undef if the execute failed. Instead, store that return value in a separate variable if desired and check it for success before calling fetchrow_array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文