【发布时间】:2017-08-10 04:14:40
【问题描述】:
当我在共享主机服务器中配置数据库时出现此错误
mysqli_connect(): (28000/1045): 用户 'username'@'localhost' 的访问被拒绝(使用密码:YES)
但它在本地主机中正常工作。
<?php
session_start();
if($_SERVER['HTTP_HOST']=="localhost")
{
$serverIp="localhost";
$userName="user1";
$password="XXXXX";
$dbname="example";
}else
{
$serverIp="localhost";
$userName="username";
$password="password";
$dbname="dbname";
}
$cn=mysqli_connect($serverIp,$userName,$password) OR Die("Couldn't Connect - ".mysql_error());
$link=mysql_select_db($dbname,$cn)or Die("Couldn't SELCECT - ".mysql_error());
?>
【问题讨论】:
-
The hostname localhost has a special meaning. It is bound to the use of Unix domain sockets. It is not possible to open a TCP/IP connection using the hostname localhost you must use 127.0.0.1 instead.-php.net/manual/en/mysqli.quickstart.connections.php 你也在混司机。
标签: php