Данные из запроса PDO ничего не возвращают - вдруг перестал работать - PullRequest
0 голосов
/ 12 марта 2020

не уверен, почему это не работает, внезапно перестал работать сегодня случайно. $ row по какой-то причине ничего не возвращает, и когда я пытаюсь отформатировать дату, я получаю сообщение об ошибке, поскольку она недействительна.

Любая помощь приветствуется.

     $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $conn->prepare("SELECT * FROM notifications");
    $stmt->execute();

    $result = $stmt -> fetchAll();

    foreach( $result as $row ) {
        $recipient = $row['recipient'];
        $day = $row['day'];
        $month = $row['month'];
        $year = $row['year'];
        $hour = $row['hour'];
        $minute = $row['minute'];


//Now we need to convert the times for this row into meaningful data
        $date = $day . "." . $month . "." . $year . " " . $hour . ":" . $minute . ":45";
        echo "<br/><br/>";

        echo "Date: " . $date;
        $dateObject = DateTime::createFromFormat('d.m.Y H:i:s', $date);
        $formattedDate = $dateObject->format('Y-m-d H:i:s');

        //Get current time
        $currentDate = new DateTime("now", new DateTimeZone('Australia/Perth'));
        $currentDate = $currentDate->format('Y-m-d H:i:s');

        //Now we have current date and time, as well as date and time from table of db.
        //Lets compare the times.

        if ($formattedDate < $currentDate) {
            //License expired
            sendPushNotifcation($recipient);
            $stmt = $conn->prepare("DELETE FROM notifications WHERE `recipient` ='".$recipient."'");
            $stmt->execute();
        }


    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...