1

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.

1
  • This does not sound WordPress related. Dec 14, 2016 at 23:07

1 Answer 1

1

Try this one. This is connection object created to use in wordpress

$mydb = new wpdb( 'username', 'password', 'my_database', 'localhost' );

and if it is way that you want to go check in codex $wpdb function 'select' to select database when do queries. Hope it help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.