php mysqli affected rows returns 0 when it should return a positive integer
suggest changeVersions
This note was tagged for PHP 5.5.
Introduction
This script is designed to handle reporting devices (IoT). When a device is not previously authorized (in the devices table in the database), the new device is added to a new_devices table. An update runs, and if affected_rows returns less than 1, the code inserts.
When a new device reports, the first time $stmt->affected_rows runs it returns 0. Later calls return 1, then 1, 0, 2, 2, 2, 0, 3, 3, 3, 3, 3, 3, 0, 4, 0, 0, 6, 6, 6, and so on.
An UPDATE that matches a row but writes the same values reports 0 changed rows. MYSQLI_CLIENT_FOUND_ROWS makes affected_rows count matches instead. The page does not show the script behind that sequence.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents