<?php
require('config.php'); 
date_default_timezone_set('America/Toronto');
$db='myappts_accountofemailsandtexts'; 
try{
$linkID1 = new PDO('mysql:host=localhost;dbname='.$db, "myappts_admin", "Taals123!@#");
$linkID1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Setting ERRMODE
$linkID = new PDO('mysql:host='.Config::DB_HOST.';dbname='.Config::DB_NAME, Config::DB_USERNAME, Config::DB_PASSWORD);
$linkID->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Setting ERRMODE
$startofmonth = date("Y-m-d", strtotime("first day of previous month"));
$endofmonth= date("Y-m-d", strtotime("last day of previous month"));
$monthname = date('F', strtotime(date("Y-m-d", strtotime("first day of previous month"))));

$test=$linkID->query('SELECT count(id) as countid FROM `texts_sent` where date_sent BETWEEN '. "'".$startofmonth.' 00:00:00'."'".'  AND '. "'".$endofmonth.' 23:59:59'."'")->fetchAll(PDO::FETCH_ASSOC);

 $dataone = [
                'countoftexts' => $test[0]['countid'], 
                'segmentsprice' => '',
                'pharmacy' => Config::COMPANY_FIRST_NAME.' '.Config::COMPANY_LAST_NAME,
                'month' =>$monthname,
                ];
        $sqlone = "INSERT INTO `smsreport`(`pharmacy`, `countoftexts`, `segmentprice`, `month`) VALUES (:pharmacy, :countoftexts, :segmentsprice, :month)";
        $stmtone= $linkID1->prepare($sqlone);
        $stmtone->execute($dataone);
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}



?>