2
I need to test if the query made everything went well or if there was an error. I tried however I did not find anything that satisfies what I need.
Example:
I submitted an sql in the database, and it was done correctly, but there was an error in the number field, in the sql of Insert it was empty. O Try/catch
will not be able to catch the error, it was submitted but was not effective.
I need to know this, whether or not she was made.
In case it is an UPDATE and IT mysql_affected_rows
works perfectly, it will return the affected lines just by making a if
if it’s >0
was successful if not, there was some mistake.
Put Quey on the question.
– user28595
It could be any one. From Insert, from delete, from uptade, any query. I just need to know if it was successful or not
– Renan Rodrigues
Look at your field in mysql if you are with
not null
PHP did not error "because probably this field accepts "null data"– RFL
@Rafaelacioly You don’t understand what I want. I need to know if there is a mechanism to know if there was an error in the sql inserted, or if everything went well. The number case is just an example I gave to understand what I want.
– Renan Rodrigues
@Renanrodrigues when you run a query it returns automatically
true
orfalse
, use aif
if you want to confirm the execution! if Voce says it appears an error in the browser then look for enable the error in php.ini and useerror_reporting(E_ALL)
– RFL
So this is not to intercept, you want to check if the query was executed as expected by the application, yet the query can be executed without errors, but not as expected by the application. And you yourself answered your question on the final lines, although citing PDO in the tag and the function you exemplified has nothing to do with PDO.
– user28595
Look at that answer on Soen. -> http://stackoverflow.com/a/11820939/5524514
– user28595
mysqli_error($conexao)
or$conexao->error
are responsible for storing and returning errors in a query, if any. There are also other functions responsible for the errors, see this.– Edilson
mysqli_error($conexao)
? the question has the PDO tag, unless you got it wrong.– rray
It’s PDO anyway, but I’ve managed to fix it, thank you all
– Renan Rodrigues