The *.bat file did the trick. and kicking it off through Task Scheduler. Initially I had the bat file pointing to the incorrect directory which is why some features weren't working. My next step, is to clean my code, and beautify the mail using base64 and html.
php C:\Apache_Directory\htdocs\my_phpscript.php
My Script... And yes, I know it's not very clean / perfect, it still has a lot of work, but for now it's doing what I need it to do:
<?php
$sql1 = "USE database_name";
$sql2 = "TRUNCATE TABLE my_table";
$sql3 = "LOAD DATA LOCAL INFILE 'DataImport//import_file.csv'
REPLACE INTO TABLE my_table
CHARACTER SET latin1
FIELDS TERMINATED BY ','
IGNORE 1 LINES
(`record_number`
, `module_name`
, `action_date`
, `location`
, `type_of_outlet`
, `user_name`
, `store_code`
, `outlet_name`
, `line_question`
, `line_field_id`
, `line_value`
, `brand_code`
, `brand`);";
/* $sql4 = "SELECT COUNT(creation_time) FROM my_table
WHERE DATE(creation_time) = DATE_SUB(CURRENT_DATE(), INTERVAL 0 DAY)"; */
$con=mysqli_connect("localhost","root","mysqlpassword","database");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
};
$result1 = mysqli_query($con, $sql1);
$result2 = mysqli_query($con, $sql2);
$result3 = mysqli_query($con, $sql3);
if (mysqli_affected_rows($con) > 1) {
$message ="". mysqli_affected_rows($con). " rows were successfully added to the my_table table!";
} else {
$message = "" . mysqli_error($con). "has caused the update to fail";
};
echo $message;
// To send HTML mail, the Content-type header must be set
require("PHPMailerAutoload.php"); // path to the PHPMailerAutoload.php file.
require("class.phpmailer.php");
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Name1 <[email protected]>, Name2<[email protected]>' . "\r\n";
$headers .= 'From: Report Server <[email protected]>' . "\r\n";
$subject = 'Data Import Resultt' ."\r\n";
$mail = new PHPMailer();
$mail->IsSMTP(true);
$mail->Mailer = "smtp";
$mail->Host = "smtp.host.co.za";
$mail->Port = 587; // 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->CharSet = "UTF-8";
$mail->SMTPOptions = array( // Bypass security verification on e-mail. WARNING: When using this method,
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->From = '[email protected]';
$mail->FromName = 'Reports Server';
$mail->AddAddress('[email protected]', 'Name1');
$mail->AddAddress('[email protected]', 'Name2');
$mail->AddAddress('[email protected]', 'Name3');
$mail->Subject = $subject;
$mail->Body = $message."\r\n";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
exit;
} else {
echo 'Message has been sent.';
}
mysqli_close($con);
?>
curl,wgetorfetchthen you could schedule that command instead.