“Record has changed since last read in table” is MariaDB error 1020. Treat the current database unit of work as failed: roll it back when possible, discard uncertain connection state, and retry the complete idempotent operation rather than only the last statement.
Last updated: November 2, 2026.
<?php
for ($attempt = 1; $attempt <= 3; $attempt++) {
try {
$pdo->beginTransaction();
updateInventory($pdo, $itemId, $quantity);
$pdo->commit();
break;
} catch (PDOException $error) {
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
if (($error->errorInfo[1] ?? null) !== 1020 || $attempt === 3) {
throw $error;
}
usleep(random_int(100000, 400000));
}
}The retry encloses the full transaction and uses bounded randomized backoff. In a connection pool or abstraction layer, retire the connection if its transaction state no longer matches the server.
Understand what changed during the read
MariaDB documents error 1020 as ER_CHECKREAD: a record changed since it was last read. Its HANDLER documentation notes that stepped scans can encounter this when another operation changes the table between reads.
Capture the table name, statement type, storage engine, transaction isolation level, and concurrent operations. Do not log complete row contents or credentials. If the error follows an upgrade, reproduce it with the exact server and database-driver versions before changing application retry policy.
Retry only when repetition is safe
MariaDB’s ROLLBACK documentation explains that rollback ends the transaction and removes its SQL-data changes. A retry must begin a new transaction and reload current data. Do not continue using values read before the failure.
Use a unique constraint, request identifier, or other idempotency control when the unit creates records. Keep email, payments, and remote API calls outside the retried database transaction. If a framework does not classify error 1020 as retryable, handle the driver code at the transaction boundary rather than hiding it inside a repository method. Continue with recovering DBAL transactions, reading PDO driver errors, and resetting failed MySQL connections.