Wordpress PHP调用MySQL过程挂起

时间:2018-11-07 11:26:07

标签: php mysql wordpress

下面描述了我的过程,但是我的问题是,通过phpmyAdmin执行该过程可以成功运行,但是如果直接在Wordpress中调用,它将挂起。

我已经确定,在该过程中尝试包括循环(REPEAT,WHILE等)的任何尝试都会导致它在从wordpress调用时挂起(请参阅第一个具有REPEAT循环的过程,第二个没有REPEAT循环)。任何解决此问题的建议都是我的问题,因为我需要能够针对给定的频率(每月,每周等)在2个日期之间的每个日期循环播放。

我已经定义了一个MySQL过程(如下所示),以在每次付款日期的行中插入直接借记付款时间表,如下所示。

我已经定义了一个Wordpress插件PHP代码段来调用该过程,该过程使用使用Elementor页面构建器定义的短代码来调用。

例如 直接付款抬头表

Name,        Date From,  Date To,    Frequency (M)onthly etc., Amount
SWW Water,   12/11/2018, 12/11/2019, M, £50.00

计划表

Name,      PaymentDate Amount
SWW Water, 12/11/2018, £50.00
SWW Water, 12/12/2018, £50.00
etc. to
SWW Water, 12/11/2020, £50.00

过程InsertScheduleRows

BEGIN

DECLARE currdate    DATE;
DECLARE enddate     DATE;
DECLARE userid      CHARACTER;
DECLARE codearg     CHARACTER;
DECLARE frequency   CHARACTER;

SELECT *, 
    @currdate   := DATE_FORMAT(transactiondd.date_from, "%Y-%m-%d"), 
    @enddate    := DATE_FORMAT(transactiondd.date_to, "%Y-%m-%d"),
    @frequency  := transactiondd.frequency,
    @codearg    := transactiondd.code,
    @userid     := transactiondd.user_id

FROM
  transactiondd
WHERE 
    updated = 'n';

SET currdate    = @currdate;
SET enddate     = @enddate;
SET codearg     = @codearg;
SET userid      = @userid;
SET frequency   = @frequency;

DELETE FROM 
    scheduledd
WHERE
    code    = @codearg
AND
    user_id = @userid;

REPEAT

SELECT currdate;

INSERT INTO scheduledd
( code, name, paydate, amount, user_id, account_id, transactiondd_id ) 
SELECT code, name, `currdate`, amount, `userid`, account_id, id 
FROM 
    transactiondd
WHERE 
    updated = 'n';
CASE frequency
    WHEN 'D' THEN SET currdate = DATE_ADD(currdate,INTERVAL 1 DAY);
    WHEN 'W' THEN SET currdate = DATE_ADD(currdate,INTERVAL 7 DAY);
    WHEN 'M' THEN SET currdate = DATE_ADD(currdate,INTERVAL 1 MONTH);
    WHEN 'Q' THEN SET currdate = DATE_ADD(currdate,INTERVAL 1 QUARTER);
    WHEN 'A' THEN SET currdate = DATE_ADD(currdate,INTERVAL 1 YEAR);
END CASE;

UNTIL currdate > enddate 

END REPEAT;    
END

一旦工作,我需要向过程中添加代码,以便在将行成功插入到计划表中后将transactiondd.updated标志更新为“ y”

Wordpress插件PHP代码段成本计划更新

global $wpdb;    
   $result = $wpdb->get_results("
    CALL
    `InsertScheduleRows`()
");                           

print_r($result);

上面的插件使用以下形式的短代码调用

[wbcr_php_snippet id =“ 14613”]

在此先感谢您的帮助。

**此程序仅在我省略REPEAT UNTIL END REPEAT行**的情况下才有效,**

所以看来悬挂是用那些线条做的!!

BEGIN

DECLARE currdate    DATE;
DECLARE enddate     DATE;
DECLARE userid      CHARACTER;
DECLARE codearg     CHARACTER;
DECLARE frequency   CHARACTER;

SELECT *, 
    @currdate   := DATE_FORMAT(dm_transactiondd.date_from, "%Y-%m-%d"), 
    @enddate    := DATE_FORMAT(dm_transactiondd.date_to, "%Y-%m-%d"),
    @frequency  := dm_transactiondd.frequency,
    @codearg    := dm_transactiondd.code,
    @userid     := dm_transactiondd.user_id

FROM
  dm_transactiondd
WHERE 
    updated = 'n';

SET currdate    = @currdate;
SET enddate     = @enddate;
SET codearg     = @codearg;
SET userid      = @userid;
SET frequency   = @frequency;

DELETE FROM 
    dm_scheduledd
WHERE
    code    = @codearg
AND
    user_id = @userid;

INSERT INTO dm_scheduledd
(code,name,type_id,paydate,amount,user_id,account_id,transactiondd_id) 
SELECT code, name, type_id, `currdate`, amount, `userid`, account_id,id 
FROM
    dm_transactiondd
WHERE 
    updated = 'n';

CASE frequency
    WHEN 'D' THEN SET currdate = DATE_ADD(currdate,INTERVAL 1 DAY);
    WHEN 'W' THEN SET currdate = DATE_ADD(currdate,INTERVAL 7 DAY);
    WHEN 'M' THEN SET currdate = DATE_ADD(currdate,INTERVAL 1 MONTH);
    WHEN 'Q' THEN SET currdate = DATE_ADD(currdate,INTERVAL 1 QUARTER);
    WHEN 'A' THEN SET currdate = DATE_ADD(currdate,INTERVAL 1 YEAR);
END CASE;
END

科林

0 个答案:

没有答案