How can a MSSQL query be executed every 3 hours using PHP?

To execute a MSSQL query every 3 hours using PHP, you can use a combination of PHP's sleep function and a loop to continuously run the query at the specified interval. You can also use a cron job to schedule the PHP script to run at regular intervals.

<?php
$serverName = "your_server_name";
$connectionOptions = array(
    "Database" => "your_database",
    "Uid" => "your_username",
    "PWD" => "your_password"
);

while (true) {
    $conn = sqlsrv_connect($serverName, $connectionOptions);
    $tsql = "SELECT * FROM your_table";
    $stmt = sqlsrv_query($conn, $tsql);
    
    // Process the query results here
    
    sqlsrv_free_stmt($stmt);
    sqlsrv_close($conn);
    
    sleep(10800); // Sleep for 3 hours
}
?>