PHP script can’t connect to Database on port 3307

Question

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,

<?php
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="https://www.wptricks.com/question/php-script-cant-connect-to-database-on-port-3307/">

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

Leave an answer