get_results("SELECT date FROM wp_financialdata_history ORDER BY DATE DESC LIMIT 1"); if (!empty($lastDate)) $lastDate = strtotime($lastDate[0]->date); else $lastDate = strtotime('1995-01-01'); foreach ($history['Time Series (Daily)'] as $date => $day) { $oDate = strtotime($date); // Skip current day datas if ($oDate === strtotime(date('Y-m-d'))) continue; // Skip already in base datas if ($oDate <= $lastDate) continue; $open = $day['1. open']; $high = $day['2. high']; $low = $day['3. low']; $close = $day['4. close']; $volume = $day['5. volume']; $wpdb->insert( 'wp_financialdata_history', [ 'date' => $date, 'open' => $open, 'high' => $high, 'low' => $low, 'close' => $close, 'volume' => $volume ], [ '%s', '%f', '%f', '%f', '%f', '%f', '%d' ] ); } } function email($email, $subject, $message) { $headers[] = 'From: Groupe LDC '; wp_mail($email, $subject, $message, $headers); }