How to check if Oracle query returned any rows in PHP and validate

Jyotishgher Astrology
By -
0

 

How to check if Oracle query returned any rows in PHP and validate


oci_num_rows

(PHP 5, PHP 7, PHP 8, PECL OCI8 >= 1.1.0)

oci_num_rows — Returns number of rows affected during statement execution

Gets the number of rows affected during statement execution.

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.


<?php

$conn = oci_connect('', '', '');  

if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$ENTER_BY=$_REQUEST['ENTER_BY'];
$ITEMID=$_REQUEST['ITEMID'];
$response = array();

$sqlCHECK  = oci_parse($conn, "select LIKE_FLAG from  OLX.SP_FAV where ENTER_BY='$ENTER_BY' and ITEMID ='$ITEMID'");
oci_execute($sqlCHECK);
 $objResult = oci_fetch_array($sqlCHECK);
   $LIKE_FLAG =$objResult["LIKE_FLAG"]; 
  
  if  ($LIKE_FLAG =="Y")
{
         $response["success"] = 2;
$response["message"] = "Already Added";
        echo json_encode($response);
}
else
{
  //$SQL  = oci_parse($conn, " UPDATE OLX.SP_FAV SET LIKE_FLAG='Y', VIEW_FLAG='Y' WHERE ENTER_BY='$ENTER_BY' AND ITEMDID='$ITEMID'");
  $sql  = oci_parse($conn, "INSERT into OLX.SP_FAV(ITEMID,ENTER_BY,LIKE_FLAG,VIEW_FLAG) values('$ITEMID','$ENTER_BY','Y', 'Y')");

   $row=oci_execute($sql) or die(oci_error($sql));
   
       if  ($row)
             
$response["success"] = 1;
$response["message"] = "Successfully.";
        echo json_encode($response);
 
else 
{
        $response["success"] = 0;
        $response["message"] = "Failed to insert.";
        echo json_encode($response);
}
}






   
    


?>


 

 

Post a Comment

0Comments

Post a Comment (0)