0

Straight from the mysqli book:

<?php
/* Prepared statement, stage 2: bind and execute */
$id = 1;
if (!$stmt->bind_param("i", $id)) {
    echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}

if (!$stmt->execute()) {
    echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
?>

The problem is $stmt->error doesnt return anything on false!

echo $stmt->error; returns nothing blank!!

Dre_Dre
  • 745
  • 2
  • 6
  • 15
  • This may not be feasible in your project, but you can use `PDO` and configure it to throw exceptions on errors. – Tomasz Kowalczyk Feb 06 '16 at 19:20
  • @ Tomasz thats not an option for me at this time. – Dre_Dre Feb 06 '16 at 19:27
  • You may have a more serious error earlier in the your script execution that you are not seeing output from. At the top of your script, `error_reporting(E_ALL); ini_set('display_errors', 1);` always when developing, testing, or debugging code. There may also have been an error on the MySQLI object before or during `prepare()`. Assuming that object is `$conn`, check `echo $conn->error;` but You must first verify there were no other errors. – Michael Berkowski Feb 06 '16 at 20:12
  • You can also [configure mysqli to throw exceptions](http://stackoverflow.com/questions/14578243/turning-query-errors-to-exceptions-in-mysqli), but again I suspect earlier errors. – Michael Berkowski Feb 06 '16 at 20:13
  • I figured it out. I was checking $stmt->error if bind_param is false but bind_param does not set $stmt->error on false. The php manual claims it does but it does not! bind_param will return a warning if not executed correctly or the number of parameter types does not match the number of parameters. – Dre_Dre Feb 06 '16 at 21:33

1 Answers1

0

I was checking $stmt->error if bind_param is false but bind_param does not set $stmt->error on false. The php manual claims it does but it does not! bind_param will return a warning if not executed correctly or the number of parameter types does not match the number of parameters.

Dre_Dre
  • 745
  • 2
  • 6
  • 15