PHP script can’t connect to Database on port 3307


I can connect to mysql just fine with my port number through the command line like so:

mysql -h ##.##.##.## -P 3307 -u wpuser -p

I have a php file that tries to connect to the DB,

include("/path to wordpress directory/wp-config.php");
$conn = new mysqli( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME );

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

and I keep receiving this error:

Connection failed: Unknown MySQL server host '##.##.##.##:3307' (1)

It does not seem to be able to connect to that host/port even though I successfully can through the command line.

I have tried manually writing the DB credentials in my $conn variable so i know that is not the issue.


>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="">

PHP script can't connect to Database on port 3307</a>
Curious_one 4 years 0 Answers 37 views 0

Leave an answer