0
votes

On Windows Server 2008 R2, I am trying to set up a scheduled task to automatically run a PHP script which then adjusts the SQlite database. I am using SQlite as I need to use a database file. Whenever I run the script, it returns this error:

But when I run it in the web browser, it works perfectly.

My code is:

$db = new PDO("sqlite:server_status.db");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "SELECT * FROM stats";  
$results = $db->query($sql);  

foreach($results as $row) {  
    print_r($row);  
}  
1
It seams like your database does not contain table 'stats'. First create the table in sqlite database. - oleksii.svarychevskyi
It exists. It displays it correctly in the web browser. - Brodie
Then it seems might be a security issue. What user runs it in schedule task? Does that user have access permission to your db file? - Iqbal
It runs it as SYSTEM, and SYSTEM has full control. - Brodie

1 Answers

0
votes

I'm no expert with PDO or SQLITE but looking at your console output it seems that your current working directory is c:/windows/system32 but that is not your web root.

Therefore PDO will be looking for your database file at: c:/windows/system32/server_status.db which i presume is not the correct path.

Either define your sqlite database location as a full absolute path starting with C:\, or change your current directory to the folder containing the sqlite database file.