在mysql中,num_rows将返回SELECT语句中所选记录的数量。我现在正在使用PDO用于SQL服务器,我正在尝试找到一个等效的函数。我尝试了以下但是他们没有工作/给我所追求的。
$sql = "select * from tracker WHERE tms_key='575'";
$result = $conn->query($sql);
$count = $result->fetchColumn());
echo '$count: '.$count.'<br>';
foreach ($result as $row){
echo $row['cucm_tmsDeviceName'];
}
这只是输出:
$count: 575
第二种方法:
$sql = "select * from tracker WHERE tms_key='575'";
$result = $conn->query($sql);
$count = $result->rowCount();
echo '$count: '.$count.'<br>';
foreach ($result as $row){
echo $row['cucm_tmsDeviceName'];
}
输出:
$count: -1
GMVC AR BA VICENTE LOPEZ COBALT