I am a newbie of PHP and I would like to create a php file that can autorun on the windows server at a specific time.
any idea to achieve??
My PHP File
JavaScript
x
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
Anyidea, Thank you very much.
Advertisement
Answer
You may execute a php on windows machine thru the command line:
JavaScript
“php c:[directory][folder][phpscript].php”.
So if you want the machine to execute it every day at a specified time, please put the command into the windows scheduler and set the time.