[英]How can I call this stored procedure in PHP?
我需要調用一個Oracle存儲過程並檢索其輸出變量,但是我不確定如何從PHP執行此操作。 我也在使用Laravel框架。
到目前為止,這就是我所擁有的。
$db = DB::connection('oracle');
$stmt = $db->getPdo()->prepare("EXEC jgreen.person_match(p_first_name => 'Bob'
, p_last_name => 'Mitchell'
, p_middle_name => ''
, p_birth_date => to_date('1982-02-09', 'YYYY-MM-DD')
, p_gender => null
, p_email => 'test@gmail.com'
, p_phone => null
, p_ssn_last_4 => null
, p_id_out => ?
, p_suspend_out => ?
, p_status_out => ?
, p_message_out => ?)");
$stmt->bindParam(1, $id);
$stmt->bindParam(2, $suspend);
$stmt->bindParam(3, $status);
$stmt->bindParam(4, $message);
$stmt->execute();
echo $status . ' ' . $message . ' ' . $pidm . ' ' . $suspend;
目前我正在
oci_bind_by_name():ORA-01036:非法變量名稱/編號
但我什至不確定我是否可以正確建立查詢。
嘗試這個
$db = DB::connection('oracle');
$stmt = $db->getPdo()->prepare("EXEC jgreen.person_match(p_first_name => :first_name
, p_last_name => :last_name
, p_middle_name => :middle_name
, p_birth_date => to_date(:birth_date, 'YYYY-MM-DD')
, p_gender => :gender
, p_email => :email
, p_phone => :phone
, p_ssn_last_4 => :ssn
, p_id_out => :id_out
, p_suspend_out => :suspend_out
, p_status_out => :status_out
, p_message_out => :message_out)");
$stmt->bindValue(':first_name', 'Bob');
$stmt->bindValue(':last_name', 'Mitchell');
$stmt->bindValue(':middle_name', '');
$stmt->bindValue(':birth_date', '1982-02-09');
$stmt->bindValue(':gender', null);
$stmt->bindValue(':email','test@gmail.com');
$stmt->bindValue(':ssn', null);
$stmt->bindParam(':id_out', $id);
$stmt->bindParam(':suspend_out', $suspend);
$stmt->bindParam(':status_out', $status);
$stmt->bindParam(':message_out', $message);
$stmt->execute();
echo $status . ' ' . $message . ' ' . $pidm . ' ' . $suspend;
看起來您正在定義一個看起來像PHP的數組以傳遞參數,但是我可以肯定地說這在Oracle中無效。 而是將存儲過程作為一系列參數而不是數組來調用:
$stmt = $db->getPdo()->prepare("EXEC jgreen.person_match(
'Bob',
'Mitchell',
'',
to_date('1982-02-09', 'YYYY-MM-DD'),
null,
'test@gmail.com',
null,
null,
?,
?,
?,
?
)");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.