0

My site has been working for 3 years perfectly and I have not made any change recently, neither to the site or database. But today it suddenly shows "Internal Server Error". I have been testing and it only fails when trying to connect to database (MySQL). Database is accessible from MySQLWorkbench or even from another site. I also have been tested with different databases. Site fails when trying to connect:

$conn = new mysqli($servername, $username, $password, $dbname);

I also have been testing with this:

$conn = mysqli_connect($servername, $username, $password, $dbname);

Also, I changed to PDO:

$mysql_connect_str = "mysql:host=$dbhost;dbname=$dbname; charset=utf8";
$dbConnection = new PDO($mysql_connect_str, $dbuser, $dbpass);

But none of those worked. There's not even need to execute a query or insert; only one of those lines is enough to fail and show Internal Server Error. Unfortunately I can't access to logfile since I'm working in a shared hosting. Can you please help me?

  • 2
    which error message exactly do you get? – nbk Apr 24 '21 at 01:00
  • What version of PHP is your host running? You can check by uploading a simple file `` and viewing it. – Skrrp Apr 24 '21 at 01:25
  • 1
    What does `mysqli_connect_error()` report after the connection attempt has failed? – Tangentially Perpendicular Apr 24 '21 at 01:38
  • I'm getting this "Internal Server Error. The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error." More information about this error may be available in the server error log. – Rotoplas Apr 24 '21 at 01:39
  • PHP version is 7.2.24 – Rotoplas Apr 24 '21 at 01:40
  • It doesn't even catch mysqli_connect_error(). It just wait for about 10 seconds and then shows "Internal Server error". It doesn't show any exception. – Rotoplas Apr 24 '21 at 01:46
  • Version looks fine. It also looks like your host is hiding the exact error from you. This is good for production environments, bad for debugging. Try wrapping your `mysqli_connect` with `try { [mysqli_connect ...]} catch (\Exception $e) { var_dump($e->getMessage()); die(); }` and see what is printed out. – Skrrp Apr 24 '21 at 01:49
  • Has the PHP version changed? I know my hosting site deprecates PHP versions once in a while. What I do is setup an Apache with the same version as the hosting company uses to test my code before an upgrade (which is announced well in advance). That being said, confirm your connection parameters with your hosting company. That might have changed (or something is expired in your account?). – Nic3500 Apr 24 '21 at 03:31

0 Answers0