PHP script in windows task scheduler

北慕城南 提交于 2019-12-11 07:32:46

问题


I wrote php script which executed successfully as a web page in the browser. But when I schedule the script using windows task scheduler, the script will run successfully (with no error in windows task scheduler) but result nothing in the database; it should update some rows.

Here is the script:

<?php
$con = mysqli_connect("xxx", "xxx", "xxx");
mysqli_select_db($con, "xxx");

$tns = "  
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = xxx))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = xxx.xxx.xxx.xx)
    )
  )
       ";
if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    };
$conn = oci_connect("xxx", "xxx", $tns);

if (!$conn)
    {
    $m = oci_error();
    echo $m['message'], "\n";
    exit;
    }
  else
    {

    $Orcle_Sql = "select ID,E_OFFICIAL_NAME,Password
                           from xxx";
    $array = oci_parse($conn, $Orcle_Sql);
    oci_execute($array);
    while ($row = oci_fetch_array($array))
        {
        $ID = $row[0];
        $Password = $row[2];

        $sql = "UPDATE students_info set password='$Password' WHERE ID= '$ID'";
        $Update_query = mysqli_query($con, $sql);
        }

    }
mysqli_close($con);
oci_close($conn);
?>

Why does running the script behave different in browser than in windows task scheduler?


回答1:


I solve it by running my PHP script through batch file.

and scheduling the batch file in Windows task scheduler.

this post helped me so much:

http://www.devside.net/wamp-server/running-php-scripts-as-cron-jobs-on-windows



来源:https://stackoverflow.com/questions/40969009/php-script-in-windows-task-scheduler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!