Question

what will be the condition of if , where i want to execute some command inside if ,if there is no row returned by the query.

<?php
  include_once('config.php');
  $db = oci_new_connect(ORAUSER,ORAPASS,"localhost/XE");
  $sql="select * from table_1 where id=3";
  $result=oci_parse($db,$sql);
  oci_result($result);

  if()
  {

  }
  else
  {

  }
?>
Was it helpful?

Solution

you could use oci_fetch:

// parse/bind your statement

if (oci_fetch($your_statement)) {
    ... // do something when there is rows
}    
else {
    ... // do something when there is no rows
}

OTHER TIPS

After assigning the bind values with oci_parse(), you need to run the query with oci_execute(). This is the function definition:

bool oci_execute ( resource $statement [, int $mode = OCI_COMMIT_ON_SUCCESS ] )

Returns TRUE on success or FALSE on failure.

Putting it all together:

<?php

$stmt = oci_parse($conn, $sql);
$res = oci_execute($stmt);
if( !$res ){
    $error = oci_error($stmt);
    echo "Error: " . $error['message'] . "\n";
}else{
    echo "OK\n";
}

?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top