简体   繁体   English

PHP Oracle oci_num_rows结果0

[英]PHP Oracle oci_num_rows result 0

I have a question about query in Oracle : 我对Oracle中的查询有疑问:

The problem is, the result of oci_num_rows is always 0. 问题是, oci_num_rows的结果始终为0。

and here is my code so far : 到目前为止,这是我的代码:

  $query = "SELECT IP_ADDRESS, STATUS FROM SEIAPPS_IP_ADDRESS WHERE IP_ADDRESS='$ip'";
  $result = oci_parse($c1, $query);
  oci_execute($result);
  echo $found = oci_num_rows($result);

To make it sure, I try to clear the condition "WHERE IP_ADDRESS='$ip'" . 为确保确定,我尝试清除条件"WHERE IP_ADDRESS='$ip'" Still same with the result is 0 whereas in my table there are some data. 结果仍然是0,而我的表中有一些数据。

Any advice ? 有什么建议吗?

Use this: 用这个:

$query = "SELECT IP_ADDRESS, STATUS FROM SEIAPPS_IP_ADDRESS WHERE IP_ADDRESS='$ip'";
$result = oci_parse($c1, $query);
oci_execute($result);
$numrows = oci_fetch_all($result, $res);
echo $numrows." Rows";

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. 对于SELECT statements此函数将返回通过oci_fetch*()函数提取到缓冲区的行数。

Try this to check either your the credentials of your connection are correct or not. 尝试执行此操作以检查您的连接凭据是否正确。

<?php
$conn = oci_connect("hr", "welcome", "localhost/XE");
if (!$conn) {
    $e = oci_error();   // For oci_connect errors do not pass a handle
    trigger_error(htmlentities($e['message']), E_USER_ERROR);
}
?>

For anyone else who fell into this trap, here's a simple summary of what the oci_fetch_all method will return. 对于陷入此陷阱的其他人,这是oci_fetch_all方法将返回的内容的简单摘要。

$s = oci_parse($conn, "
          SELECT 1 AS A FROM DUAL 
    UNION SELECT 2 AS A FROM DUAL 
    UNION SELECT 3 AS A FROM DUAL 
    UNION SELECT 4 AS A FROM DUAL
");
oci_execute($s);
echo "records fetched: ". oci_num_rows($s)."\n";

oci_fetch($s);
echo "records fetched: ". oci_num_rows($s)."\n";

oci_fetch($s);
echo "records fetched: ". oci_num_rows($s)."\n";

oci_fetch_all($s, $out);
echo "records fetched: ". oci_num_rows($s)." out count: ". count($out['A']) . "\n";

will output: 将输出:

records fetched: 0
records fetched: 1
records fetched: 2
records fetched: 4 out count: 2

So oci_num_rows is incremental, each call to oci_fetch will increment the counter by one (assuming there is at least one more record to fetch), and oci_fetch_all will fetch all remaining rows and put them into the $out buffer. 因此oci_num_rows是增量的,每次对oci_fetch调用都会使计数器增加一(假设至少oci_fetch_all获取一条记录),而oci_fetch_all将获取所有剩余的行并将其放入$out缓冲区。

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

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