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

前端之家收集整理的这篇文章主要介绍了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.

猜你在找的Perl相关文章