Jump to content

Mysql Create Event


mrt003003

Recommended Posts

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. :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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 :)

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.