当前位置: 动力学知识库 > 问答 > 编程问答 >

Can't connect to mysql db using [email protected] in a mamp environment

问题描述:

I'm working on a MAC in a MAMP environment.

so when i try to connect to the database i get this error

$this->db = mysqli_connect('localhost', 'root', '');

I can log in with PhpMyAdmin as the root user.

mysqli_connect(): (28000/1045): Access denied for user

'root'@'localhost' (using password: YES)

my root user is set like this

user: root

machine: localhost

password: no

global rights: ALL PRIVILEGES

grant: yes

Does anyone know how to resolve this problem?

网友答案:

The PHP Manual here says about the password field:

If not provided or NULL, the MySQL server will attempt to authenticate the user against those user records which have no password only. This allows one username to be used with different permissions (depending on if a password as provided or not).

So, either do mysqli_connect($host, $user); or mysqli_connect($host, $user, null);

网友答案:

you have to call mysqli_connect without a password parameter, else php tries to authenticate the user using the empty string as password. try

mysqli_connect($host, $user);

only, withouth the ''.

分享给朋友:
您可能感兴趣的文章:
随机阅读: