perl – 当我使用DBI为非select语句准备/执行时,如何获取受影响的行数?

根据 DBI文档,似乎我只能通过do方法获取受影响的行数.

$rows_affected = $dbh->do("UPDATE your_table SET foo = foo + 1");

如果使用prepare / execute,如何获得相同的结果?

解决方法

从有关 execute method in DBI的文档:

For a non-“SELECT” statement,“execute” returns the number of rows affected,if kNown. If no rows were affected,then “execute” returns “0E0”,which Perl will treat as 0 but will regard as true. Note that it is not an error for no rows to be affected by a statement. If the number of rows affected is not kNown,then “execute” returns -1.

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...