The only way to get an update statement to truly fail is to put invalid data in fields (alpha characters in numeric fields, nulls in non-nullable fields, etc.) You can also get errors if you try and use values in FK fields which donât correspond to a record on the foreign table - IF you have the FK constraints defined properly.
For inserts, you have the same possibilities as above, plus duplicate errors on primary key fields, and not providing values in non-null fields.
If the field âphoto_approvedâ is defined as a tinyint, then how in the world can this query runâŚ
UPDATE member
SET photo_approved = '8888', last_activity = now()
WHERE id = 57
âŚwithout an error?!
photo_approved = 127
And how can this query runâŚ
UPDATE member
SET photo_approved = 'xxx', last_activity = now()
WHERE id = 57
âŚwithout an error?!
photo_approved = 0
And more importantly, how in the world do I get mysqli_stmt_affected_rows() to error out and return -1 like the Manual says it should when there is an error??? :wall:
What type of failures are you looking for besides syntax errors or invalid data?
Also, just because there might be data submitted that you donât want doesnât mean it canât be added to a database. Thereâs a difference between invalid types of data going into a database (like trying to insert text into a numeric database column) and not getting the values you want or expect (like 888888 instead of 8).
Youâre only going to get -1 when a query fails to run because of an error. If the query runs then the output of that function with be 0 if nothing was affected or a number >= 1. From the manual:
An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records where updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query returned an error.
Writing a gobbly-gook query does not break any PHP code, since it isnât PHP. It should cause MySQL to return with an error. I thought that was what you wanted. I donât understand what you mean by âthat wonât even runâ.