【问题标题】:Passing variables from SQL proceedure to PHP将变量从 SQL 过程传递给 PHP
【发布时间】:2023-04-11 11:35:01
【问题描述】:

我正在尝试创建一个将结果返回到 php 页面的 sql 过程。

我希望能够从 php 中调用如下程序

call procedure_name($var1)

将运行此脚本:

-- ---------------------------------------------------------------------------------
-- pUIGetCliStmtGenFlag
--
-- This procedure returns the status of the Trading Period:
--
-- ---------------------------------------------------------------------------------


drop procedure if exists pUIGetCliStmtGenFlag;
delimiter //

create procedure pUIGetCliStmtGenFlag(
IN pTradingPeriodMonth      DATE
)
MODIFIES SQL DATA
COMMENT 'Checks if the TP has been closed'
begin

  SELECT trading_period_month, 
         dt_end, 
         amt_traded_system_ccy
  FROM   ca_trading_period
  WHERE  trading_period_month=$var1

-- If amt_traded_system_ccy is NULL give the TP an open status otherwise mark as closed

  IF amt_traded_system_ccy is NULL

    $tpstatus='open'

  ELSE

    $tpstatus='closed'

end;
//

delimiter ;

然后我希望能够在 php 脚本的其余部分中使用 $tpstatus

我知道这很简单,但这对我来说是全新的,我找不到正确的方法

【问题讨论】:

    标签: php sql variables procedure


    【解决方案1】:

    您必须从 php 调用存储过程,然后使用过程的 OUT 参数取回值。

    请按照以下说明操作:

    https://stackoverflow.com/a/48161/1291428

    【讨论】:

      猜你喜欢
      • 2019-02-16
      • 1970-01-01
      • 2013-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-14
      相关资源
      最近更新 更多