有DBI
没有办法确定SELECT语句的执行语句句柄是否将返回任何行而不从中获取?
就像这样:
use DBI;
...
my $sth = $dbh->prepare("SELECT ...");
$sth->execute;
if (..$sth will return at least one row...) {
...
} else {
...
}
Run Code Online (Sandbox Code Playgroud)
我想在$sth will return at least one row
不执行任何获取方法的情况下执行测试$sth
.
注意 - 我不需要精确的行数(即$sth->rows
),我只需要知道是否$sth->rows
> 0.
$ sth-> rows仍然是你最好的选择.如你所说,只需检查它是否超过0.
if ($sth->rows > 0){
# magic here!
}
Run Code Online (Sandbox Code Playgroud)
除了!DBI文档说,在获取所有行之前,这对于选择的状态是不可靠的.无法确定提前获取的行数.如果你需要知道这个建议是先做一个
select count(*) from <table>
Run Code Online (Sandbox Code Playgroud)
请参阅DBI文档的此部分.
归档时间: |
|
查看次数: |
8335 次 |
最近记录: |