PHP Version 5.6.40, internal error for connect mysql

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
nitiphone2021
php-forum Active User
php-forum Active User
Posts: 31
Joined: Fri Jan 08, 2021 8:10 pm

Sat Jun 05, 2021 5:27 am

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: Select all

$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
simonbrahan
php-forum Fan User
php-forum Fan User
Posts: 137
Joined: Mon Jun 08, 2020 2:00 am
Contact:

Sun Jun 06, 2021 5:09 am

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: Select all

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
nitiphone2021
php-forum Active User
php-forum Active User
Posts: 31
Joined: Fri Jan 08, 2021 8:10 pm

Sun Jun 06, 2021 6:59 am

This is the error I receive

Code: Select all

Fatal error: Call to undefined function mysqli_report() in /home/newlinkbdbcom/public_html/app/webroot/test.php on line 5
simonbrahan
php-forum Fan User
php-forum Fan User
Posts: 137
Joined: Mon Jun 08, 2020 2:00 am
Contact:

Sun Jun 06, 2021 12:31 pm

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?
nitiphone2021
php-forum Active User
php-forum Active User
Posts: 31
Joined: Fri Jan 08, 2021 8:10 pm

Sun Jun 06, 2021 4:46 pm

I think you tell me run the command last time?

Code: Select all

<?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);
}
?>
simonbrahan
php-forum Fan User
php-forum Fan User
Posts: 137
Joined: Mon Jun 08, 2020 2:00 am
Contact:

Sun Jun 06, 2021 11:37 pm

OK. That's odd. Can you remove the try ... catch wrapper and try it again?

Code: Select all

    $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.
Post Reply