远程连接到WAMP MySQL没有连接

时间:2017-10-12 09:03:09

标签: php mysql wamp

我正在使用WAMP在Windows Server 2016上运行一个网站。该站点有一个mysql数据库,我已经为用户添加了密码,并给出了静态IP和%

每当我尝试使用php字符串连接时,我会收到错误,如下所示

  

警告:mysql_connect():无法连接到MySQL服务器   '的 &#39。; (13)无法连接

当我使用MySQL Workbench时,我可以登录MySQL DB没有问题

我目前正在使用以下代码

$host="***.***.***.***"; // Host IP Address I even tried it by :3306 port after IP
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="gs"; // Database name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

我已将以下内容添加到phpmyadmin.conf文件中

Directory "c:/wamp/apps/phpmyadmin4.0.4/">
    Options Indexes FollowSymLinks ExecCGI
    AllowOverride all
    Order Allow,Deny 
    Allow from all
    Allow from 0.0.0.0
    Allow from 127.0.0.1

它拒绝让我访问任何建议将不胜感激

我已经使用了mysqli,这是我收到的错误,这是我的代码

$servername = "154.0.***.***";
$username = "***";
$password = "***";
$port = "3306";

// Create connection
$conn = new mysqli($servername, $username, $password, $port);

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

警告:mysqli :: mysqli():( HY000 / 2002):权限被拒绝   第30行/home/www/e-track.biz连接失败:权限被拒绝

第30行

$conn = new mysqli($servername, $username, $password, $port);

1 个答案:

答案 0 :(得分:0)

Hi,

Please use below code:- if this code will not work then please check the server setting.

<?php 
$servername = "154.0.***.***";
$username = "***";
$password = "***";
$db_name="gs";

$con = @mysqli_connect($servername, $username, $password,$db_name);
if (mysqli_connect_errno())
{
    echo "Database connection error: ".mysqli_connect_error();
}
else
{
    echo "Connected successfully";
}
?>