PHP Oracle oci_num_rows 结果 0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18957148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Oracle oci_num_rows result 0
提问by Asean Jazz
I have a question about query in Oracle :
我有一个关于 Oracle 查询的问题:
The problem is, the result of oci_num_rowsis 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'". Still same with the result is 0 whereas in my table there are some data.
为了确保这一点,我尝试清除条件"WHERE IP_ADDRESS='$ip'"。结果仍然是 0 而在我的表中有一些数据。
Any advice ?
有什么建议吗?
回答by Code L?ver
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";
回答by Moeed Farooqui
This function does not return number of rows selected! For SELECT statementsthis 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);
}
?>
回答by StampyCode
For anyone else who fell into this trap, here's a simple summary of what the oci_fetch_allmethod 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_rowsis incremental, each call to oci_fetchwill increment the counter by one (assuming there is at least one more record to fetch), and oci_fetch_allwill fetch all remaining rows and put them into the $outbuffer.
oci_num_rows增量也是如此,每次调用oci_fetch都会将计数器加一(假设至少还有一条记录要提取),oci_fetch_all并将提取所有剩余的行并将它们放入$out缓冲区。

