我试图从php调用MySql函数。当我在MySql中测试查询时,它工作正常,但是当我从php尝试它时,我没有得到任何结果。
我的职能:
DROP FUNCTION IF EXISTS AddWorkDays;
DELIMITER $$
CREATE FUNCTION AddWorkDays
(
WorkingDays INT,
StartDate DATETIME
)
RETURNS DATETIME
BEGIN
DECLARE Count INT;
DECLARE i INT;
DECLARE NewDate DATETIME;
SET Count = 0;
SET i = 0;
WHILE (i < WorkingDays) DO
BEGIN
SELECT Count + 1 INTO Count;
SELECT i + 1 INTO i;
WHILE DAYOFWEEK(DATE_ADD(StartDate,INTERVAL Count DAY)) IN (6,7) DO
BEGIN
SELECT Count + 1 INTO Count;
END;
END WHILE;
END;
END WHILE;
SELECT DATE_ADD(StartDate,INTERVAL Count DAY) INTO NewDate;
RETURN NewDate;
END;
$$
DELIMITER ;
和我的php调用查询
$res = mysql_query($conn,"UPDATE `subscribes` SET `end_date`= AddWorkDays(1,`end_date`) where `end_date` >= '2016-09-18'");