简体   繁体   English

PHP代码未通过批处理文件运行

[英]PHP Code not running through Batch File

This File(home.php) is running properly but when i am runnng this file through batch file in windows scheduler. 这个文件(home.php)运行正常,但是当我通过Windows调度程序中的批处理文件运行此文件时。 It's not running. 它没有运行。

    <?php

//error_reporting(0);
$con = mysqli_connect("localhost","root","","test"); 

$handle = @fopen("organisation.csv", "r");

while (($data = fgetcsv($handle, 20000, ",")) !== FALSE) 

 {  
 $tt="INSERT INTO upload (organization, entity, credit_limit, days) VALUES(
     '".mysqli_real_escape_string($con,$data[0])."',
     '".mysqli_real_escape_string($con,$data[1])."',
     '".mysqli_real_escape_string($con,$data[2])."',
     '".mysqli_real_escape_string($con,$data[3])."'
     )";
     mysqli_query($con,$tt) or (mysqli_error($con)); 

}
echo "done";

?> 

Below is the batch file code: 以下是批处理文件代码:

c:\xampp\php\php.exe -f "c:\xampp\htdocs\home.php"

I'm not sure how windows scheduler works, but if it's close to cronjobs in ubuntu, you should use absolut paths to files. 我不确定Windows调度程序是如何工作的,但是如果它接近ubuntu中的cronjobs,你应该使用absolut路径来存档。 The script is probably not executed in it's own directory. 该脚本可能没有在它自己的目录中执行。

So try this: 试试这个:

$handle = @fopen("c:\xampp\htdocs\organisation.csv", "r");

Also you could add: 你也可以添加:

echo "$tt <br>";

befor you execute the SQL-statment to see what the statement acually is. 你执行SQL-statment来查看语句的真实含义。 If you get a statment but nothing is added into your database, copy the satemant and try it manually, to see prosibble errors. 如果您获得了一个声明,但没有任何内容添加到您的数据库中,请复制该声明并手动尝试,以查看繁琐的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM