Error at this MySQL query

Discussion in 'MySQL' started by hip_hop_x, Apr 30, 2009.

  1. #1
    I got a problem with this query, error at line 3.
    SQL query:
    
    CREATE EVENT event ON SCHEDULE EVERY1 SECOND DO BEGIN UPDATE village_buildings SET done =1 WHERE (
    endtime < UNIX_TIMESTAMP( )
    );
    
    MySQL said: Documentation
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 
    Code (markup):
    Can someone help me to fix this sql code? I can't see why it wrong, if i try this command
    UPDATE village_buildings SET done=1 WHERE(endtime<UNIX_TIMESTAMP());
    Code (markup):
    alone works fine.

    
    CREATE EVENT event ON SCHEDULE EVERY 1 SECOND DO
    BEGIN
    	UPDATE village_buildings SET done=1 WHERE(endtime<UNIX_TIMESTAMP());
    	
    	DECLARE ppid INT;
    	DECLARE action,build TEXT;
    	DECLARE curl CURSOR FOR SELECT name,town_id,action FROM village_buildings WHERE done=1;
    	
    	OPEN cur1;
    	  BEGIN
    		DECLARE EXIT HANDLER FOR NOT FOUND BEGIN END;
    		LOOP
    		  FETCH cur1 INTO build,ppid,action;
    		  IF action == 'upgrade' THEN
    			UPDATE village_players_villages SET build=build+1 WHERE id=ppid;
    		  ELSE
    			UPDATE village_players_villages SET build=build-1 WHERE id=ppid;
    		  END IF;
    		END LOOP;
    	  END;
    	CLOSE cur1;
    END
    Code (markup):

     
    hip_hop_x, Apr 30, 2009 IP
  2. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #2
    Try this :
    $sql = mysql_query("UPDATE village_buildings SET done='1' WHERE endtime<UNIX_TIMESTAMP()");
    PHP:
     
    ActiveFrost, Apr 30, 2009 IP
  3. hip_hop_x

    hip_hop_x Active Member

    Messages:
    522
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #3
    i said already cause that code is working fine
     
    hip_hop_x, Apr 30, 2009 IP