php - 如何在 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;
推荐阅读
- javascript - 如何处理来自另一个js而不是service-worker的推送通知?
- mongodb - 使用 ODBC 驱动程序使用 power bi 连接 mongodb
- python-venv - 未找到“importlib-resources>=1.0”发行版,virtualenv 需要该发行版
- excel - 条件格式 - 多条件、InStr 检查、最小值(第 2 部分)
- android - 在文件选择器库中,即使 requestLegacyExternalStorage =“true”,Android 10 也会显示占位符图像?
- python - 猜数字游戏中的最后一次猜测和尝试/除外
- logging - Splunk“stats”命令只考虑项目的一个子集
- c# - C# Task.Delay(1).Wait() 死锁,但前提是在另一个任务中
- ios - App Store Connect 中的可本地化信息在发布后重置
- html - 如何将由代码创建的 html 表转换为 json 对象?AngularJS