I have a question about query in Oracle :
The problem is, the result of oci_num_rows
is always 0.
and here is my code so far :
$qu
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.
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);
}
?>
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";
For anyone else who fell into this trap, here's a simple summary of what the oci_fetch_all
method will return.
$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.