$rowcount = 'SELECT COUNT(1) FROM (select * from isk.edi_site where postal_code = 123456)';
$stmt= oci_parse($conn, $rowcount);
oci_execute($stmt);
$num_row = oci_fetch_assoc($stmt);
$num = count($num_row, COUNT_RECURSIVE);
echo $num;
计数并返回数字“1”。当我在Oracle SQL开发人员中使用相同的SQL查询时,它会超过4000+计数。我的错误在哪里?列数运作良好..
答案 0 :(得分:5)
COUNT()
查询只返回一行,因此您需要从oci_fetch_assoc()
调用中获取它。你正在做的是计算结果集中的行,它们总是为1。
$row = oci_fetch_assoc($stmt);
echo $row['COUNT(1)'];
或者给计数一个别名:
SELECT COUNT(1) mycount FROM ...
$row = oci_fetch_assoc($stmt);
echo $row['MYCOUNT'];