1

I just read this it explains clearly for object oriented style error handling.

This page also explains the same.

I want to know how to find whether a prepared statement fails, and what is the error.

$stmt = mysqli_prepare(ConnectionObject,Query);
if($stmt == false)
{
    // Found statement fails
    // How to find what is the error
    // mysqli_stmt_error($stmt); It will fail because $stmt is boolean[false].
}

How to find the exact error?

Community
  • 1
  • 1
Gibbs
  • 21,904
  • 13
  • 74
  • 138

1 Answers1

1

You could use mysqli_error:

$stmt = mysqli_prepare(ConnectionObject, $query);
if(!$stmt) {
    printf("Cannot prepare query <%s>. Error message: %s\n", 
           $query, mysqli_error(ConnectionObject));
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Thanks Mureinik. Can you please explain `
    string '' (length=0)`. I just got this from `var_dump(mysqli_error(ConnectionObject))`
    – Gibbs Oct 04 '15 at 16:48
  • @GopsAB this is a var_dump of an empty string (`''`), indicating there has been no error before you called `mysqli_error`. – Mureinik Oct 04 '15 at 16:52
  • 1
    What is the reason for down-vote? – Gibbs Oct 05 '15 at 08:26