存储过程适用于本地但不会在服务器上执行

时间:2011-03-10 21:51:17

标签: php mysql stored-procedures localhost

我写了一个存储过程,在我的本地机器上工作,但在服务器中,它不会执行!帮助

会很棒

存储过程是

DROP PROCEDURE `ASKUS_INSERT`//
CREATE DEFINER=`root`@`localhost` PROCEDURE `ASKUS_INSERT`(
 SENDERCONSUMERID INT(11),
 QUESTION_POSTED TEXT,
 DESCRIPTION_POSTED TEXT,
 NETWORK_ID INT(11),
 COMMTYPEID INT(11),
 CONSUMERID INT(11),
 CATEGORY_ID INT(11),
 ACTIONID INT(11),
 QUESTION_SLUG TEXT
)
BEGIN
     DECLARE LASTINSERTEDID INT DEFAULT 0;
     DECLARE GETTIPSAMOUNT INT DEFAULT 0;
     DECLARE GETTIPSAMOUNTCONSUMER INT DEFAULT 0;
     DECLARE SETTIPSAMOUNTCONSUMER INT DEFAULT 0;
     DECLARE CHECKCOUNTTIPSEXIST INT DEFAULT 0;

     SELECT COUNT(*) INTO CHECKCOUNTTIPSEXIST FROM ACTION_ENTERPRISE_MAPPING WHERE ACTION_ID = ACTIONID;
     IF CHECKCOUNTTIPSEXIST  > 0 THEN
        SELECT SUM(TIP_AMOUNT) INTO GETTIPSAMOUNT FROM ACTION_ENTERPRISE_MAPPING WHERE ACTION_ID = ACTIONID;
     ELSE
         SET GETTIPSAMOUNT  = 0;
     END IF;     


     SELECT CONSUMER_TIPS INTO GETTIPSAMOUNTCONSUMER FROM CONSUMER_PROFILE WHERE CONSUMER_ID = SENDERCONSUMERID;
     SET SETTIPSAMOUNTCONSUMER = GETTIPSAMOUNTCONSUMER + GETTIPSAMOUNT;


     INSERT INTO NETWORK_COMMUNICATIONS (COMMUNICATIONS_ID,SENDER_CONSUMER_ID,NETWORK_COMM_TYPE_ID,PARENT_COMMUNICATIONS_ID,IS_ACTIVE,LAST_MOD_TIME,CONSUMER_ID) VALUES ('',SENDERCONSUMERID,COMMTYPEID,'0','1',NOW(),CONSUMERID);

     SET LASTINSERTEDID = LAST_INSERT_ID();

     UPDATE CONSUMER_PROFILE SET  CONSUMER_TIPS =  SETTIPSAMOUNTCONSUMER  WHERE CONSUMER_ID = SENDERCONSUMERID;
     INSERT INTO CONSUMER_ACTION_LOG (ACTION_LOG_ID,ACTION_ID,CONSUMER_ID,TIPS_AMOUNT,LAST_MOD_TIME,COMMUNICATIONS_ID,COMM_TYPE_ID) VALUES ('',ACTIONID,SENDERCONSUMERID,GETTIPSAMOUNT,NOW(),LASTINSERTEDID,ACTIONID);     


     INSERT INTO NETWORK_COMMUNICATIONS_MESSAGE (NETWORK_COMMUNICATION_MESSAGE_ID,COMMUNICATIONS_ID,SUBJECT,MESSAGE,IS_ACTIVE,LAST_MOD_TIME,QUESTION_SLUG) VALUES ('',LASTINSERTEDID,QUESTION_POSTED,DESCRIPTION_POSTED,'1',NOW(),QUESTION_SLUG);


     INSERT INTO COMMUNICATION_INTEREST_MAPPING (ID,CONSUMER_INTEREST_EXPERT_ID,CONSUMER_ID,COMMUNICATION_ID,IN_NETWORK,LAST_MOD_TIME) VALUES ('',CATEGORY_ID,SENDERCONSUMERID,LASTINSERTEDID,NETWORK_ID,NOW());    

     IF SENDERCONSUMERID != 0 AND CONSUMERID != 0 AND SENDERCONSUMERID != CONSUMERID THEN
     INSERT INTO CONSUMER_NOTIFICATION (CONSUMER_NOTIFICATION_ID,CONSUMER_ID,SENDER_CONSUMER_ID,ACTION_ID,COMMUNICATIONS_ID,IS_ACTIVE,LAST_MOD_TIME) VALUES  ('',CONSUMERID,SENDERCONSUMERID,COMMTYPEID,LASTINSERTEDID,'1',NOW());
     END IF;
END

它说有很多语法错误和未知变量。在这种情况下,它不应该在我的localhost中工作。但它确实做到了!我很困惑!

1 个答案:

答案 0 :(得分:2)

如果这样做,你不应该更改分隔符吗?现在你有;中途可能会造成麻烦吗?

您可以查看this manual page以获取如下示例:

mysql> delimiter //

mysql> CREATE PROCEDURE simpleproc (OUT param1 INT)
    -> BEGIN
    ->   SELECT COUNT(*) INTO param1 FROM t;
    -> END//
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;

如您所见,分隔符首先设置为“//”。你的第一行意味着你正试图做那样的事情。也许你只是忘了粘贴分隔线?

这个:

DROP PROCEDURE `ASKUS_INSERT`// 

只适用于设置为'//'的分隔符。您应该(参见示例)也可能以//结尾。