PHP Oracle Ref Cursor

时间:2009-10-26 16:48:09

标签: php oracle stored-procedures conditional while-loop

好的,我是PHP / Oracle连接器的新手。我想要做的是调用一个简单的存储过程,它接受一个id号并返回一个值。如果有匹配,它工作正常,但我不能为我的生活弄清楚如果没有匹配,添加条件逻辑。基本上,如果有匹配项,请为其设置$ strategy,如果没有匹配项,则将$ strategy设置为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);

1 个答案:

答案 0 :(得分:0)

怎么样

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