How to get one row from Oracle to PHP?

I want to know how to extract a single row from Oracle in PHP?

Chedck my script -: I want to extract one row from the ITEM_INFO table and compare these values ​​with the $ sku and $ code .. Logic variables. I applied that it works in Mysql but it does not work in Oracle ...

Every time $ sku and $ code contain diff. so I just need to compare them with the ITEM_INFO table, and if it matches, update the flag for the same ...

$query_fetch = "SELECT ITEM_NAME,SITE_CODE FROM app.ITEM_INFO WHERE ITEM_FLAG = 'N'";
$stmt = oci_parse($conn,$query_fetch);
oci_execute($stmt);
while(($row = oci_fetch_array($stmt, OCI_BOTH))) 
{   
    $ITEM_NAME = ($row["ITEM_NAME"]);                       
    $SITE_CODE = ($row["SITE_CODE"]);   

    if(($ITEM_NAME === $sku) && ($SITE_CODE === $code))
    {   
              $query_ora_update = "UPDATE app.ITEM_INFO SET ITEM_FLAG= 'Y', LAST_UPDATE_DATE = sysdate WHERE ITEM_NAME = '$sku' AND SITE_CODE = '$code' AND ITEM_FLAG = 'N' ";
                                            $parse_result = oci_parse($conn,$query_ora_update);
    $result = oci_execute($parse_result);
    oci_commit($conn);
    oci_close($conn);
    }
 }

plz lead me ...

+3
source share
3 answers

Basically, you just need to remove the loop while.

, (+ , +, SQL, ):

$query_ora_update = "UPDATE app.ITEM_INFO SET ITEM_FLAG= 'Y', LAST_UPDATE_DATE = sysdate WHERE ITEM_FLAG = 'N'";
$parse_result = oci_parse($conn, $query_ora_update);
$result = oci_execute($parse_result);

oci_commit($conn);
oci_close($conn);
+2

Oracle, where :

ROWNUM = 1

, , , "ifs", where .

+2

Oracle equivalent mysql_fetch_assoc, oci_fetch_assoc :)

$parsed = ociparse($conn, $sql);
while ($row = oci_fetch_assoc($parsed))
{
    // your logic here
}
+1
source

All Articles