为什么我收到“无法调用方法“fetchrow_array”?没有包或对象引用”?
我已经安装了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$res
不是DBI
的对象实例。尝试运行 ref $res :它应该返回一个空字符串。您的
$res
很可能包含“受影响的行”的数量。$res
is not an object instance ofDBI
. Try runningref $res
: it should return an empty string.Your
$res
most likely contains the number of "affected rows".您不应该
在该语句之前说 $res 是执行成功后调用 fetchrow_array 所需的语句句柄,但上面将其替换为execute() 的返回值,即受影响的行数如果成功,则 undef 如果执行失败。相反,如果需要,可以将该返回值存储在单独的变量中,并在调用 fetchrow_array 之前检查它是否成功。
You should not be saying
$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.