我在Godaddy windows托管上制作简单的mysqli连接到我的数据库,我的代码如下:
<?PHP
error_reporting(E_ALL & ~(E_STRICT|E_NOTICE));
$host = 'localhost';
$user = 'root_user_name';
$password = 'root_user_pass';
$db = 'my_database';
$cxn = MysqLi_connect($host,$user,$password) or
die(MysqLi_connect_error()); // <<<<<< line 9
MysqLi_select_db($cxn, $db ) or die(MysqLi_connect_error());
die('test');
我确定授予的用户名和密码以及数据库名称,我的所有凭据都是正确的,但我收到此错误:
Warning: MysqLi_connect(): (HY000/1045): Access denied for user
‘root_user_name’@’localhost’ (using password: YES) in
G:\path\to\file\index.PHP
on line 9 Access denied for user ‘root_user_name’@’localhost’ (using
password: YES)
我使用wamp服务器在localhost上使用相同的数据库名称和凭据,我没有太多进入IIS服务器和Windows托管..任何帮助将不胜感激.
解决方法:
我曾经遇到过这个问题,只需在连接数据库时设置主机中数据库服务器的真实IP地址即可解决.要获取IP地址,请登录您的主机帐户并访问数据库,然后单击管理您想要的数据库,这将带您到PHPMyAdmin.在右侧有一个标题为Database Server的块,您可以在第一个列表项中找到服务器IP地址.在$host而不是localhost中使用它:
$host = '51.51.51.51'; // <<<< just a fake IP address for the example
我有很多艰难的时间来找出问题所在,我甚至联系了支持部门并得到了这个回复:
Joshua – I think the permissions are the cause of the issue. Once you
have them properly updated, the problem should go away.
有时解决方案比您想象的更接近!!