tengo el siguiente código donde estoy validando receipts en un api y luego hago un update en mi base de lo que haya cambiado de ese receipt; lo que me esta pasando es que en este momento en la base tengo más de 100001000 resultados pero me esta actualizando solo uno después de que hace la verificación en la api, actualiza uno y tira un warning y no hace nada más.
require_once '../db_connect.php';
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "SELECT * FROM jsonapple WHERE status='freetrial' AND expires_date_formatted_pst < (CURDATE() + INTERVAL 7 DAY) OR status='Active' AND expires_date_formatted_pst < (CURDATE() + INTERVAL 7 DAY) OR status='freetrial' AND auto_renew_status='false'";
$result = mysqli_query($conn, $query);
$sql = '';
if ($result) {
$count = 0;
while ($row = mysqli_fetch_assoc($result)) {
$count++;
$latest_receipt = $row["latest_receipt"];
$url = 'https://xxx/apple/verifyReceipt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'token=xxx&receiptb64=' . $latest_receipt . '');
$result = curl_exec($ch);
//print $result;
curl_close($ch);
if (($count % 200) == 0) {
sleep(5);
}
$obj = json_decode($result, true);
if ($obj["auto_renew_status"] == 1) {
$auto_renew_status = 'true';
} else {
$auto_renew_status = 'false';
}
$status = $obj["status"];
if (isset($obj["expiration_intent"])) {
$expiration_intent = $obj["expiration_intent"];
} else {
$expiration_intent = '';
}
if (isset($obj["is_in_billing_retry_period"])) {
$is_in_billing_retry_period = $obj["is_in_billing_retry_period"];
} else {
$is_in_billing_retry_period = '';
}
if ($status == 0 || $status == 21006) {
if ($status == 21006) {
$status_row = 'Expired';
} else {
if ($obj["auto_renew_status"] == 1 && $obj["latest_receipt_info"]["is_trial_period"] == 'true') {
$status_row = 'Active';
}
ifelseif ($obj["auto_renew_status"] == 0 && $obj["latest_receipt_info"]["is_trial_period"] == 'true') {
$status_row = 'FreeTrial';
}
ifelseif ($obj["auto_renew_status"] == 1 && $obj["latest_receipt_info"]["is_trial_period"] == 'false') {
$status_row = 'Active';
$payment = 1;
}
ifelseif ($obj["auto_renew_status"] == 0 && $obj["latest_receipt_info"]["is_trial_period"] == 'false') {
$status_row = 'Expired';
}
}
} else {
$status_row = 'Review response';
}
$sql .= "UPDATE jsonapple SET status='$status_row', expiration_intent='$expiration_intent', auto_renew_status='$auto_renew_status', is_in_billing_retry_period='$is_in_billing_retry_period', status_code ='$status', payment='$payment' WHERE latest_receipt='$latest_receipt'; ";
}
if ($conn->query($sql) === TRUE) {
echo "Successfully" . $sql . "<br>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();