I've just come across this problem when making multiple insert queries using prepared statements.
I have a loop which runs through 102 iterations and each time it triggers an insert query:
$sql = "INSERT INTO xxx SET town=?, city=?, ...";
$stmt = $conn->prepare($sql);
while(... <= 102)
{
$stmt->bind_param("sss", $town, $city, ...);
$stmt->execute();
}
No errors are picked up during execution but only 98 entries are recorded in the database. I have run this several times and always 98 entries are inserted. 4 are missing somewhere.
If I replace the prepared statement with a standard query, leaving everything else the same, i.e.
while(... <= 102)
{
$sql = "INSERT INTO xxx SET town='$town', city='$city', ...";
mysqli_query($conn, $sql)
}
...then it works fine and all 102 items are inserted into the database.
Since the prepared statements queries do not report any errors, I have no idea why it is missing 4 queries.
How could I go about investigating this?
Since the data is from a trusted source I can just use mysqli_query but I'd rather know what's going on in case I come across this in the future.