首页 > 解决方案 > 如何在 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: 非法变量名/编号

但我什至不确定我是否从一开始就构建了查询。

标签: phpsqloraclelaravelplsql

解决方案


试试这个

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

推荐阅读