最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mysql - PHP script can't connect to Database on port 3307

programmeradmin2浏览0评论

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.

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 Improve this question asked Dec 14, 2016 at 20:34 Curious_oneCurious_one 112 bronze badges 1
  • This does not sound WordPress related. – czerspalace Commented Dec 14, 2016 at 23:07
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论