phpmysqlphpmyadminmampmysql-connect

mysql_connect() always denies access


I have phpMyAdmin running with MAMP, and I am finding it impossible to use mysql_connect().

$_db_connect = mysql_connect("root", "localhost");

Produces an error in php_error.log: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'root'@'localhost' (using password: NO) in /....../common.lib.php on line 19

I've checked out the privileges:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION

GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION

and I am simply stumped. I've created new users with passwords just to get the same result. Strangely it always says (using password: NO), even when I attempt to connect as a user witha password:

$_db_connect = mysql_connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD);

Any advice is welcomed. Thanks!


Solution

  • You are missing the password in the function. Also, the function call is wrong. Do it like this:

    $_db_connect = mysql_connect("localhost", "root", "password");
    

    where, password is the password for your root account. It might be different.