简体   繁体   English

如何在PHP中调用此存储过程?

[英]How can I call this stored procedure in PHP?

There is an oracle stored procedure that I need to call and retrieve its output variable, but I'm not sure how to do this from PHP. 我需要调用一个Oracle存储过程并检索其输出变量,但是我不确定如何从PHP执行此操作。 I'm also using the Laravel framework. 我也在使用Laravel框架。

Here's what I have so far. 到目前为止,这就是我所拥有的。

$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;

Currently I'm getting a 目前我正在

oci_bind_by_name(): ORA-01036: illegal variable name/number oci_bind_by_name():ORA-01036:非法变量名称/编号

but I'm not even sure that I built the query right to start. 但我什至不确定我是否可以正确建立查询。

Try this 尝试这个

$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;

It looks like you're defining a PHP-looking array to pass in parameters, but I'm fairly certain that's not valid in Oracle. 看起来您正在定义一个看起来像PHP的数组以传递参数,但是我可以肯定地说这在Oracle中无效。 Instead, call your stored procedure as a series of parameters instead of an array: 而是将存储过程作为一系列参数而不是数组来调用:

$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM