使用oci_num_rows在OCI / PHP中出现问题

时间:2014-05-02 10:13:39

标签: php oci

当通过SQL的完全相同的查询返回228时,为什么下面显示0 results returned

error_reporting(E_ALL);
ini_set('display_errors', 1);

include("connection.php");

if($conn){

  $stid = oci_parse($conn, "SELECT COUNT(CustomerNo) FROM Customers");
  oci_execute($stid);

  echo oci_num_rows($stid) . " rows returned.<br />\n";

  oci_free_statement($stid);
  oci_close($conn);
}

1 个答案:

答案 0 :(得分:2)

您必须获取结果然后调用oci_num_rows。正如oci_num-rows -

的PHP手册所述

Note: This function does not return number of rows selected! For SELECT statements this function will return the number of rows, that were fetched to the buffer with oci_fetch*() functions.

因此,您的PHP代码应该是:

error_reporting(E_ALL);
ini_set('display_errors', 1);

include("connection.php");

if($conn){

  $stid = oci_parse($conn, "SELECT COUNT(CustomerNo) FROM Customers");
  oci_execute($stid);

  $numrows = oci_fetch_all($stid, $res);
  echo $numrows . " rows returned.<br />\n";

  oci_free_statement($stid);
  oci_close($conn);
}