0

I tried to catch all kind of possible errors from a database function. My code won't work for me, so maybe I think there is a error inside or i misunderstood something.

That's what i have

$appDB = new mysqli('localhost', '12344', '123456', '123456');
if ($appDB->connect_error) { die("Connection appDB failed: " . $appDB->connect_error); } 

$result = $appDB->query($query[0].' '.$table.' '.$query[1])
    or die (mysql_error().'\nAdditional Infos: $appDB->query('.$query[0].' '.$table.' '.$query[1].'); --> Result:'.$result);

That won't work - I get no errors, what I do wrong in this case?

Hope someone can explain what my error about the code is.

newbieRB
  • 137
  • 1
  • 14

1 Answers1

1

Given that $appDB is a mysqli instance, you simply need to do:

if ( !$result ) {
  echo $appDB->error`;
}

Or in your specific case (based on your code sample):

$result = $appDB->query($query[0].' '.$table.' '.$query[1])
    or die ($appDB->error."\n".'Additional Infos: $appDB->query('.$query[0].' '.$table.' '.$query[1].'); --> Result:'.$result);

See the documentation for more information: http://php.net/manual/en/mysqli.error.php

Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68
Dave Goodchild
  • 322
  • 4
  • 9