oracle 为什么oci_num_rows总是返回0?

gdrx4gfi  于 2023-08-04  发布在  Oracle
关注(0)|答案(2)|浏览(218)

我有这个问题的代码:

<?php
    include 'connection.php';

    if (oci_execute ( $stmt )) {
        //Execute cursor
        oci_execute($result);  //Or you can return the cursor.
    }

    $count=oci_num_rows($result);
    echo $count;
    if ($count != 1)
    {
    echo $count;
    echo "No record";
    }
    else
    {

   while($objResult = oci_fetch_array($result, OCI_RETURN_NULLS+OCI_ASSOC)){
   <tr>
   <td><div align="center" class="style4"><?php echo $objResult[0]; ?></div></td>
   <td><div align="center" class="style4"><?php echo $objResult[1]; ?></div></td>
   <td><div align="center" class="style4"><?php echo $objResult[2]; ?></div></td>
   <td><div align="center" class="style4"><?php echo $objResult[3]; ?></div></td>
   <td><div align="center" class="style4"><?php echo $objResult[4]; ?></div></td>
    <td><div align="center" class="style4"><?php echo $objResult[5]; ?></div></td>
     <td><div align="center" class="style4"><?php echo $objResult[6]; ?></div></td>
     <td><div align="center" class="style4"><?php echo $objResult[7]; ?></div></td>

     <td><div align="center" class="style4"><a href="updateInsForm.php?insid=<?php echo $objResult[0]; ?>">EDIT</a></div></td>
     <td><div align="center" class="style4"><a href="deleteInsForm.php?insid=<?php echo $objResult[0]; ?>">DELETE</div></td>

    <?php 
   }
   }

   oci_close($objConnect);
 ?>

字符串
问题是当我尝试输入正确的id和密码时,它返回的行为0...为什么?

qacovj5a

qacovj5a1#

问题是num_rows函数返回的是获取的项数,而不是执行的结果。从手册:
http://php.net/manual/en/function.oci-num-rows.php
注意:此函数不返回选中的行数!对于SELECT语句,此函数将返回使用oci_fetch*()函数提取到缓冲区的行数。
希望这对你有帮助。

vcirk6k6

vcirk6k62#

试试这个:

<?php
    include 'connection.php';

    if (oci_execute($stmt)) {
        // Execute cursor
        $result = $stmt; // Assign the cursor to $result
    }

    $count = oci_num_rows($result);
    echo $count;
    if ($count != 1) {
        echo "No record";
    } else {
        while ($objResult = oci_fetch_array($result, OCI_RETURN_NULLS+OCI_ASSOC)) {
            echo "<tr>";
            echo "<td><div align='center' class='style4'>" . $objResult[0] . "</div></td>";
            echo "<td><div align='center' class='style4'>" . $objResult[1] . "</div></td>";
            echo "<td><div align='center' class='style4'>" . $objResult[2] . "</div></td>";
            echo "<td><div align='center' class='style4'>" . $objResult[3] . "</div></td>";
            echo "<td><div align='center' class='style4'>" . $objResult[4] . "</div></td>";
            echo "<td><div align='center' class='style4'>" . $objResult[5] . "</div></td>";
            echo "<td><div align='center' class='style4'>" . $objResult[6] . "</div></td>";
            echo "<td><div align='center' class='style4'>" . $objResult[7] . "</div></td>";
            echo "<td><div align='center' class='style4'><a href='updateInsForm.php?insid=" . $objResult[0] . "'>EDIT</a></div></td>";
            echo "<td><div align='center' class='style4'><a href='deleteInsForm.php?insid=" . $objResult[0] . "'>DELETE</a></div></td>";
            echo "</tr>";
        }
    }

    oci_close($objConnect);
?>

字符串
将执行的游标$stmt分配给$result,而不是使用oci_execute($result)再次执行它。更正了开始和结束PHP标记,以将HTML代码 Package 在while循环中。添加了适当的echo语句来输出HTML表的行和列。正确格式化了“EDIT”和“DELETE”链接的href属性。

相关问题