DateTime-> format()不返回字符串

时间:2018-07-05 09:44:32

标签: php datetime mysqli

我一直在进行一些代码遍历,直到从API检索到一定数量的数据为止,每次使用的日期都增加1。我遇到了一个似乎无法修复的错误,我从那里得到错误:Object of class DateTime could not be converted to string

据我所知,DateTime对象上的format函数应该并且确实会返回一个字符串,但是即使格式化了它,它也不会返回。这是我的代码:

$stmt = $conn->prepare("INSERT INTO `orders` (`orderReference`,`assignedAocId`,`dropDate`) VALUES(?,?,?) ON DUPLICATE KEY UPDATE `assignedAocId`=VALUES(`assignedAocId`), `dropDate`=VALUES(`dropDate`)");
$stmt->bind_param('sis',$order_reference,$aoc_id,$date);

while(count($aoc_ids) > 0) {
    // $date = date("d/m/Y");
    $date = new DateTime();
    $date->modify("-30 days");

    $aoc_id = $aoc_ids[0];

    $run_count = 0;
    $populated_count = 0;

    while($populated_count < 2 && $run_count < 5) {
        $date = $date->modify("+1 day");
        $formatted_date = $date->format("d/m/Y"); // Keeps looping through and incrementing date but never gets data
        $session_id = generate_session_id($ch);
        curl_setopt($ch, CURLOPT_URL, "https://live3.maxoptra.com/rest/2/distribution-api/orders/getOrdersWithZone");
        curl_setopt($ch, CURLOPT_POSTFIELDS,
            "sessionID={$session_id}&date={$formatted_date}&aocID={$aoc_id}");
        if(($xml = new SimpleXMLElement(curl_exec($ch))) !== false) {
            if($xml->error->errorCode != 1016) {
                if (sizeof($xml->OrdersWithZoneResponse->orders) > 0) {
                    foreach ($xml->OrdersWithZoneResponse->orders->order as $order) {
                        $order_reference = (string)$order["referenceNumber"];
                        $stmt->execute(); // Throws the error on this line
                    }
                    $populated_count = $populated_count+1;
                }     
                $run_count = $run_count+1;
            } elseif($xml->error->errorCode == 1016) {
                handle_error("getOrdersWithZone Invocation Limit Reached");
            } else {
                handle_error("getOrdersWithZone Unknown Error Code Returned",$debug_email);
                exit();
            }
        } else {
            handle_error("getOrdersWithZone cURL Failed",$debug_email);
            exit();
        }
    }
    array_shift($aoc_ids);
}

0 个答案:

没有答案