MysticKnight Posted June 26, 2020 Share Posted June 26, 2020 I have an online store that was created with PHP and it uses MySQL on the backend. There’s a boolean field in the database that either turns the store on (enabled) or it turns the store off (disabled) when it’s toggled. My question is can I write code that would automatically toggle that boolean value at specific times of the day? Quote Link to comment Share on other sites More sharing options...
gw1500se Posted June 26, 2020 Share Posted June 26, 2020 Yes, for Linux use cron and for Windows use task scheduler. Quote Link to comment Share on other sites More sharing options...
MysticKnight Posted June 26, 2020 Author Share Posted June 26, 2020 (edited) Can you tell me more about how to do it or is there a place where I can detailed information? I’ll be using a standard Linux OS at a web hosting company. I familiar enough to modify PHP or MySQL or follow instructions, but I’m still relatively new to both. Edited June 26, 2020 by MysticKnight Quote Link to comment Share on other sites More sharing options...
MysticKnight Posted June 26, 2020 Author Share Posted June 26, 2020 I think I’m heading in the right direction here... https://www.werockyourweb.com/cron-job-mysql/ But I would still welcome and specific instructions that anyone decides to contribute. Quote Link to comment Share on other sites More sharing options...
requinix Posted June 26, 2020 Share Posted June 26, 2020 It's an online store? Online? Why should it ever be closed? Quote Link to comment Share on other sites More sharing options...
Barand Posted June 26, 2020 Share Posted June 26, 2020 Didn't you get the memo about the regulation of working hours for AI? Quote Link to comment Share on other sites More sharing options...
MysticKnight Posted June 26, 2020 Author Share Posted June 26, 2020 33 minutes ago, requinix said: It's an online store? Online? Why should it ever be closed? They only sell products that have to be picked up in person. Quote Link to comment Share on other sites More sharing options...
kicken Posted June 27, 2020 Share Posted June 27, 2020 (edited) 21 minutes ago, MysticKnight said: They only sell products that have to be picked up in person So someone can't order something to be picked up tomorrow? I do that somewhat frequently with lowes/home depot. In any case, you'd essentially just create a script to change that field. <?php $online = intval($argv[1]); $db = new PDO('mysql:host=localhost;dbname=store', 'username', 'password'); $statement = $db->prepare('UPDATE table SET online=? WHERE whatever'); $statement->execute([$online]); Then setup two cron jobs to run that script at whatever time you want to toggle the field and it's desired value # Set online=1 at 9am 0 9 * * * /usr/bin/php /home/you/toggleOnline.php 1 # Set online=0 at 5pm 0 17 * * * /usr/bin/php /home/you/toggleOnline.php 0 You'll have to get more sophisticated if you want to handle things like weekends, holidays, etc. Edited June 27, 2020 by kicken Quote Link to comment Share on other sites More sharing options...
MysticKnight Posted June 27, 2020 Author Share Posted June 27, 2020 I can’t thank you enough for your help. I’m going to use your suggestion and see if I can get it working tomorrow. I know it sounds weird, but in this case they want the shopping cart to turn off when someone isn’t available to immediately follow up on the order by phone. Quote Link to comment Share on other sites More sharing options...
requinix Posted June 27, 2020 Share Posted June 27, 2020 Quote Link to comment 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.