Issue in OCI/PHP using oci_num_rows

人盡茶涼 提交于 2019-12-25 02:47:22

问题


Why would the below show 0 results returned, when the exact same query via SQL returns 228?

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:


You have to fetch the results and then call oci_num_rows. As described on the PHP manual for oci_num-rows -

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.

Therefore your PHP code should be like:

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);
}


来源:https://stackoverflow.com/questions/23425684/issue-in-oci-php-using-oci-num-rows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!