I
I
Ivan Shumakov2019-07-30 12:26:21
PHP
Ivan Shumakov, 2019-07-30 12:26:21

Why do I get an error when I run a script using the Windows Scheduler?

On the WAMP server there is a script that takes data from the SQL server (on another computer) and writes it to MySQL. The script works when run from the site. I need to run it through the windows scheduler. I create and run a bat file, but the script stops working at the stage of connecting to the SQL server (I work with PDO) without any notification. When I remove a piece with the encoding declaration from the script, I intercept the error: "Could not find driver". Notably, the connection to MySQL (located on the same machine as PHP) runs smoothly.
Actually, a piece of code:

include_once $_SERVER['DOCUMENT_ROOT'] . "/../secure/luna_db_data.php";
try {
    $luna_pdo = new PDO($luna_db_dsn, $luna_db_username, $luna_db_password);
} catch(PDOException $e) {
    echo 'Error: ' . $e->getMessage() . '<br>';
}

include_once $_SERVER['DOCUMENT_ROOT'] . "/../secure/isa_db_data.php";

try {
    $isa_pdo = new PDO($isa_db_dsn, $isa_db_username, $isa_db_password);
} catch(PDOException $e) {
    echo 'Error: ' . $e->getMessage() . "<br>";
}
$isa_pdo->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_UTF8);

bat:
start "email reminder task" "C:\wamp64\bin\php\php7.1.29\php.exe" -f C:\www\draft\incremental_update.php

What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2019-07-30
@ivanshumakov

0) start "email reminder task" "C:\wamp64\bin\php\php7.1.29\php.exe" -f C:\www\draft\incremental_update.php>>C:\www\draft\incremental_update.log
1) For cli php, a different php.ini is used than for "through Apache", perhaps just different settings
2) Paths, check what you have in $_SERVER['DOCUMENT_ROOT'], it can generally show where to show from cli
3) Check or error output is set, maybe it writes something, but only in the log (look at the log)
so far there are no more thoughts ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question