每当我尝试使用我的凭据连接到我的数据库时,它都不会与用户名连接,例如当我尝试使用
连接到我的本地数据库时mysqli_connect("localhost","dbuser","","database")
返回
Warning: mysqli_connect(): (HY000/1044): Access denied for user ''@'localhost' to database 'database'
答案 0 :(得分:0)
您无法使用mysqli_connect()
上的所有四个参数进行连接
从上面的代码我可以告诉你
host : "localhost"
user: "dbuser"
password: ""
database name: "database"
这样做,
$conn = mysqli_connect("localhost", "dbuser", "");
mysqli_select_db($conn, "database");
// to check if you're connected, after tested and see you can take off the code below...
if ($conn) {
echo "Connected";
} else {
echo "Connection failed";
}
如果您真的想要使用上面的所有四个参数进行连接?
$conn = new mysqli("localhost","dbuser","","database");
// to check if you're connected, after tested and see you can take off the code below...
if ($conn) {
echo "Connected";
} else {
echo "Failed";
}
希望这有用吗?
答案 1 :(得分:0)
只需在这样的引号之间加一个空格" "而不是""在查询中的密码值中显示为空白,因为在编程中必须存在0(false)或1(true)的值,你不能没有任何东西并期待某些东西
这是因为您没有像root用户那样在本地phpmyadmin中为用户设置密码,也检查拼写错误