• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

MySQL DataBase automatic reset after 24 hour for Demo Mode

Asheni21

Member
Sep 23, 2022
39
22
8
I wish to create a demo mode for my CMS and is there anyway with which I can set my MySQL database automatically reset after 24 hour of time.(all my customer data should remove within 24h but without remove my demo data to)
 
You can use cron job to set a job for 24 hours. That job will have to remove all your database tables & recreate with demo content.
 
I wish to create a demo mode for my CMS and is there anyway with which I can set my MySQL database automatically reset after 24 hour of time.(all my customer data should remove within 24h but without remove my demo data to)
here is a sample script in PHP that could be used to reset the MySQL database after 24 hours of time using a cron job:
Code:
<?php

// Connect to MySQL server
$db_host = "localhost";
$db_user = "username";
$db_pass = "password";
$db_name = "database_name";

$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}

// Delete all customer data from database
$delete_customer_data = "DELETE FROM customers WHERE is_demo = 0";

if (mysqli_query($conn, $delete_customer_data)) {
  echo "Customer data deleted successfully" . PHP_EOL;
} else {
  echo "Error deleting customer data: " . mysqli_error($conn) . PHP_EOL;
}

// Close connection to MySQL server
mysqli_close($conn);

?>
To set up the cron job, you would need to add this script to your server and configure the cron daemon to run it at a specific time every day. For example, to run the script at midnight every day, you could add the following line to the crontab file:

0 0 * * * /path/to/reset_database.php
This is just a sample script and may need to be modified to fit the specific needs of your CMS
 
  • Like
Reactions: nyomancepol
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock