简体   繁体   English

将变量从SQL过程传递到PHP

[英]Passing variables from SQL proceedure to PHP

I am trying to create an sql proceedure that will return the results back to the php page. 我正在尝试创建一个SQL过程,将结果返回到php页面。

I want to be able to call the procedure as follows from the php 我希望能够从php调用以下过程

call procedure_name($var1)

which will run this script: 它将运行以下脚本:

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

I then want to be able to use $tpstatus in the rest of the php script. 然后,我希望能够在其余的php脚本中使用$tpstatus

I know this is simple but this is completely new to me and I cant find the correct method 我知道这很简单,但这对我来说是全新的,我找不到正确的方法

You have to call the stored procedure from php and THEN get the values back, using OUT parameters of the procedure. 您必须从php调用存储过程,然后使用过程的OUT参数取回值。

Please follow these instructions: 请按照以下说明进行操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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