M10TheMist
M10TheMist

Reputation: 407

Prevent default username & password from being used by php to mysql

I tried searching but the answers to similar questions didn't solve my problem.

I am trying to connect to MySQL database from a PHP code like this:

$con = mysql_connect($hostname,$username,$password);

where

$hostname = "localhost" , $username = "xxx" , $password = "yyy"

When I try to access this php page from browser, I get this error message:

Could not connect: Access denied for user 'www-data'@'localhost' (using password: NO)

I understand that www-data is the default username used by the apache webserver and it does not have a password. Since this user hasn't been configured in MySQL, connection is refused.

My question is how I could prevent the default username from getting used. I would want the php code to try connecting to MySQL using the username "xxx" and password "yyy"

Any help is greatly appreciated!

Upvotes: 3

Views: 484

Answers (1)

NewUser
NewUser

Reputation: 3819

Writing mysqli_connect() should solve your problem and use mysqli instead of mysql as suggested by teresko.

Upvotes: 1

Related Questions