繁体   English   中英

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

[英]Issue in OCI/PHP using oci_num_rows

当通过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);
}

您必须获取结果,然后调用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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM