Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (4k points)
closed by

I'm trying to connect to a remote server. I think the problem is with the port number, but when I try error reporting, I'm not getting any information.

$db_host        = 'MY.IP.ADD.RESS:3306';
$db_user        = 'user';
$db_pass        = 'password';
$db_database    = 'database'; 

$link = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a NHT_DB connection');


if (!$link) {
    die('Connect Error: ' . mysqli_connect_error());
}
else {
    echo 'Success... ' . mysqli_get_host_info($link) . "\n";
}

First, I'm not 100% confident that's the correct port. How do I find out what port mysql is set to use?

Second, mysqli_connect_error() isn't giving me anything. No number, codes, nothing. The test page just spits back Connect Error: with out as much as a code I can go look up.

closed

4 Answers

0 votes
by (13k points)
 
Best answer

To determine the MySQL port, check the configuration file. If mysqli_connect_error() doesn't provide any information, make sure error reporting is enabled in PHP configuration and the MySQL extension is enabled. Check server logs for error messages.

0 votes
by (8.7k points)

you can easily connect to  remote server by adding a port argument to the mysqli_connect function like:

$db_host        = 'Ip address';

$db_user        = 'username';

$db_pass        = 'password';

$db_database    = 'database_name'; 

$db_port        = '3306';

 

$link = mysqli_connect($db_host,$db_user,$db_pass,$db_database,$db_port);

Check out the SQL Certification by Intellipaat, to be a Pro player in your own field. 

0 votes
by (7.8k points)
First, to determine the port that MySQL is set to use, you can check the configuration file of your MySQL server. The configuration file is usually named "my.cnf" or "my.ini" and is located in the MySQL installation directory. Open the file and search for the line that starts with "port" followed by a number. This should indicate the port number that MySQL is configured to listen on.

Regarding the issue with mysqli_connect_error() not providing any information, it could be due to error reporting settings. Make sure that error reporting is enabled in your PHP configuration. You can do this by checking the value of the "error_reporting" directive in your "php.ini" file. Set it to "E_ALL" to display all types of errors, including connection errors. Additionally, check if the "display_errors" directive is set to "On". If it's set to "Off", change it to "On" to enable error display.

If you have verified that error reporting is enabled and you're still not getting any information, it's possible that the issue lies with the PHP MySQL driver or the MySQL server itself. Ensure that the MySQL extension is enabled in your PHP configuration. If it's not enabled, you can enable it by uncommenting the line "extension=mysqli" in your "php.ini" file. If the problem persists, consider checking the MySQL server logs for any relevant error messages that could shed light on the issue.
0 votes
by (11.4k points)
Find MySQL port: Check configuration file.

mysqli_connect_error(): Enable error reporting, check MySQL extension, and review server logs.

Related questions

0 votes
1 answer
asked Feb 12, 2021 in SQL by adhiraj (4k points)
0 votes
1 answer
0 votes
0 answers

Browse Categories

...