mrt003003 Posted May 31, 2011 Share Posted May 31, 2011 Hi there im tryng to get a simple example of creating a continuous event that updates a record every 5 seconds. <?php mysql_query ("CREATE EVENT player_update ON SCHEDULE EVERY 5 SECONDS DO UPDATE player SET ShipYard = '5' "); ?> Heres the structure of my table: PlayerID PlayerName ts (Time Stamp) ShipYard Could you point me in the right direction please?? Thanks for listening. Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/ Share on other sites More sharing options...
mikosiko Posted May 31, 2011 Share Posted May 31, 2011 other than a syntax error, because you are using SECONDS instead of SECOND do you have any other problem?... which one? Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223095 Share on other sites More sharing options...
mrt003003 Posted May 31, 2011 Author Share Posted May 31, 2011 There are no errors but the records are never updated to 5. I manually entered a current timestamp into the table and tested it. Later once i get this working ill update a new current time stamp every 5 seconds as well. But yeah its just not updating at all?? Do i need to set any global events?? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223104 Share on other sites More sharing options...
mrt003003 Posted May 31, 2011 Author Share Posted May 31, 2011 I got it working by adding the following line: mysql_query ("SET GLOBAL event_scheduler = 1"); Yay! Thank you Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223106 Share on other sites More sharing options...
mikosiko Posted May 31, 2011 Share Posted May 31, 2011 that means that the EVENT scheduler wasn't enabled to begin with... plus the syntax error (in case that one was not a typo) Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223116 Share on other sites More sharing options...
mrt003003 Posted May 31, 2011 Author Share Posted May 31, 2011 Hmm it really is not working correctly at all. It updates immediately and doesnt at all there after??? Then i changed: UPDATE player SET ShipYard = '5' To: UPDATE player SET ShipYard = '1' and it still updates to a 5 in the table immediately not waiting at all?? Ive restarted all my services and even retart my pc but its just not working. Whats going on? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223129 Share on other sites More sharing options...
mikosiko Posted May 31, 2011 Share Posted May 31, 2011 in your EVENT creation code you are not specifying when the event should STARTS... therefore it is executed upon creation and should be executed thereafter depending on the EVENT's definition. check the EVENT syntax post your current code and what exactly are your objectives for further help Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223158 Share on other sites More sharing options...
mrt003003 Posted May 31, 2011 Author Share Posted May 31, 2011 Heres my code : <?php mysql_query ("SET GLOBAL event_scheduler = 1"); mysql_query("CREATE EVENT player_update ON SCHEDULE EVERY 2 MINUTE DO UPDATE player SET ShipYard = 1");?> I changed it to a 2 minute interval but still its updating 5 in ShipYard and it does it straight after ShipYard is updated and a new current timestamp is set. I just need it to update ShipYards to a number every 2 minutes from the time the page loads. ITs totally strange that even thought now ShipYard is set to 1 and its updating to 5?? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223162 Share on other sites More sharing options...
mikosiko Posted May 31, 2011 Share Posted May 31, 2011 guessing.... you created your first script version saying: <?php mysql_query ("SET GLOBAL event_scheduler = 1"); mysql_query("CREATE EVENT player_update ON SCHEDULE EVERY 5 MINUTE DO UPDATE player SET ShipYard = 5");?> right? then you updated your code to say: <?php mysql_query ("SET GLOBAL event_scheduler = 1"); mysql_query("CREATE EVENT player_update ON SCHEDULE EVERY 2 MINUTE DO UPDATE player SET ShipYard = 1");?> and executed it again... right? if so... your second code should have gave you an error saying "The event player_update already exists"... which probably you didn't see it because you don't have the error reporting active in your code (include the 2 lines in my signature after your <?php line and you will see the error) .,.. therefore the original event (update every 5 second) still active. Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223170 Share on other sites More sharing options...
mrt003003 Posted May 31, 2011 Author Share Posted May 31, 2011 The first script was: <?php mysql_query ("SET GLOBAL event_scheduler = 1"); mysql_query("CREATE EVENT player_update ON SCHEDULE EVERY 5 SECOND DO UPDATE player SET ShipYard = 5");?> I tested it and it looked like it was working because 5 seconds is a short time to update a record manually. So i wanted to restest but using a longer time period to: <?php mysql_query ("SET GLOBAL event_scheduler = 1"); mysql_query("CREATE EVENT player_update ON SCHEDULE EVERY 2 MINUTE DO UPDATE player SET ShipYard = 1");?> I tested it and again it updates ShipYard to 5 and seems to be straightaway or in 5 seconds. However ive tried both of them at the same time and there is no error saying update already exists. I also have error_reporting from your signature on too.??? If its still active how to i reset it? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223171 Share on other sites More sharing options...
mikosiko Posted May 31, 2011 Share Posted May 31, 2011 as I said... if you executed those 2 codes one after the other the first one should remain active and 2nd one will give you an error (assuming that you are connecting to Mysql with the same user in the same DB). suggestions: - You should activate the EVENT scheduler using mysql configuration file (activate it just one time in one place). - You should create your EVENTS only one time using any GUI that you are familiar with (PHPMYADMIN, MYSQL-WORKBENCH are some options) - Thereafter you can use ALTER EVENT syntax in case that you need to modify your EVENT definition or change its STATUS (enable or disable it) read the link that I did provide for you in my 3rd post. Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223182 Share on other sites More sharing options...
mrt003003 Posted May 31, 2011 Author Share Posted May 31, 2011 Thank you ill check it out. But how do i delete the 1st one ON SCHEDULE EVERY 5 SECOND? because thats happening all the time. :| Thanks Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223194 Share on other sites More sharing options...
mikosiko Posted May 31, 2011 Share Posted May 31, 2011 DROP EVENT player_update; and also you can disable the EVENT scheduler SET GLOBAL event_scheduler=OFF; (or 0) Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223220 Share on other sites More sharing options...
mrt003003 Posted June 1, 2011 Author Share Posted June 1, 2011 Thank you thats brilliant! I was just a bit confused because it was running even without any create event code. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/238021-mysql-create-event/#findComment-1223420 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.