PHP Version 5.6.40, internal error for connect mysql

nitiphone2021

New member
According to I have a project need to use PHP 5.6.40 connect to mysql version 5.7.34
This URL for phpinfo()
http://newlink.bdb.com.la/app/webroot/test.php

when I try to connect it by below coding
Code:
$servername = "localhost";
$username = "user";
$password = "pass";
$db_database    = 'db_unelr'; 
$db_port        = '3306';

// Create connection
$conn = mysqli_connect($servername, $username, $password,$db_database,$db_port);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";

it's show 500 internal error.
what should I check and fix this problem? it's private host, so I can run linux command to check
 
Turn errors on so you can see what the problem is.

You should probably set mysqli to throw exceptions as well; that will stop you having to muck around with error handling code.

Code:
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
 
This is the error I receive
Code:
Fatal error: Call to undefined function mysqli_report() in /home/newlinkbdbcom/public_html/app/webroot/test.php on line 5
 
That error means you're trying to call a function - "mysqli_report" that doesn't exist. It's not written uin the code you've provided though, are you sure you've given us the correct script?
 
I think you tell me run the command last time?
Code:
<?php

//phpinfo();die;


try{
    $servername = "localhost";
    $username = "user";
    $password = "password";
    $db_database    = 'db'; 
    $db_port        = '3306';
    
    // Create connection
    $conn = mysqli_connect($servername, $username, $password,$db_database,$db_port);
    // Check connection
    if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
    }
    echo "Connected successfully";
}catch(Exception $e){
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
}
?>
 
OK. That's odd. Can you remove the try ... catch wrapper and try it again?

Code:
    $servername = "localhost";
    $username = "user";
    $password = "password";
    $db_database    = 'db'; 
    $db_port        = '3306';
    
    // Create connection
    $conn = mysqli_connect($servername, $username, $password,$db_database,$db_port);
    // Check connection
    if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
    }
    echo "Connected successfully";

If you've turned errors on, it should just print out the exception you're getting.
 
Back
Top