php - Prepared statements and bind_param error handling -


in following php code prepared statements intentionally caused error test bind_param , execute, adding $bikes.

in execute function error information returned; however, in bind_param, although error occurs, not return error information.

how error information in bind_param?

$sqlquery = "insert the_cars (cars) values (?)";  if($statement = $con->prepare($sqlquery)){      if(!$statement->bind_param("s", $cars, $bikes)){ //bikes should not here         $errors = $statement->error; //error empty     };      if(!$statement->execute()){         $errors1 = $statement->error; // error: no data supplied parameters in prepared statement     };  }else{         $errors = $con->error; } 

edited:

the php manual seems suggest in bind_param error should handled. see following part of text: example #3 insert prepared once, executed multiple times » /* prepared statement, stage 2: bind , execute */

http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

this seems position advocated in posts. example:

mysqli prepared statements error reporting

however, made several attempts, , never able description of statement error in bind_param.

you can't error (nor have gotten one) out of hasn't yet been executed, therefore second conditional statement won't throw error. need check if execution successful , not against bind_param() method.

then third (conditional statement) won't theoretically thrown error because of have in query theoretically considered being valid (query) statement.

what need remove if(!$statement) statement bind, but keep in execution part.

you receive error.

your first conditional statement if($statement = $con->prepare($sqlquery)) valid, else won't throw error since hasn't been executed.

consult following reference manuals on php.net on how query/check errors , don't try reinvent wasn't intended throw errors in first place:

in short, error handling done on query (and execution) , not on binding.

consult manual on bind_param():

there no mention or examples of error handling on method.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -