Search code examples
phpapachemysqliinternal-server-error

Class Instance throws Internal Server Error 500 (PHP, MYSQLi)


I am having a strange situation.

When a class instance is passed to a method & the class instance has not been set, the server throws a 500 error, instead of catching the error.

This happends during testing 99% of the time, but I want to make sure a user never sees it for that 1%

BTW : I have already checked my .htaccess and apache2 files <= they are correct

What do i need to change in my php.ini file or something similar to avoid a 500 error everytime this happens??

Here is some sample code :

<?php

function querysomething ($connection_to_mysql, $query) {
  try {
    $query = $connection_to_mysql->prepare("SELECT * FROM table WHERE name=?");
    $query->bind_param("s", $name);
    $execute = $query->execute();
    //etc...
    if (!$execute) {
      throw new Exception ("some error");
    }
  } catch (Exception $e) {
    //some error handling
  }
}

?>

If the $connection_to_mysql object is not instantiated, the server throws a 500 error

Do I need to check if the $connection_to_mysql actually exists everytime prior to query?


Solution

  • Use set_error_handler/set_exception_handler to display a php fatal error-specific page.