views:

248

answers:

1

Okay, I am new to PHP/Oracle connectors. What I am trying to do is call a simple stored procedure which accepts a id number and returns a value. It works fine if there is a match, but I can't for the life of me figure out how to add conditional logic if there isn't a match. Basically, if there is a match, set $strategy to it, if there isn't a match, set $strategy to be NULL.

$sql = 'BEGIN STOREDPROCEDURENAME(:v_id_number, :entries); END;';

$stmt = oci_parse($conn, $sql);

oci_bind_by_name($stmt,':v_id_number',$id_number,32);

// Create a new cursor resource
$entries = oci_new_cursor($conn);

// Bind the cursor resource to the Oracle argument
oci_bind_by_name($stmt,":entries",$entries,-1,OCI_B_CURSOR);

// Execute the statement
oci_execute($stmt);

// Execute the cursor
oci_execute($entries);

while ($entry = oci_fetch_array($entries)) {
  $strategy = $entry['STRATEGY'];
 }

oci_close($conn);
A: 

How about

$strategy = null;
if ($entry = oci_fetch_array($entries)) {
     $strategy = $entry['STRATEGY'];       
}
BeWarned