0

I am begginer and I always have this problem when I am going to move my website from my computer to host or server, some codes can't run or I always see some errors.

I created a database and I set a privilege(username and password) but I have error yet.

This is the Error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'mypassword'@'localhost' (using password: YES) in /home/qmelkir/public_html/include/connect.php on line 5 Access denied for user 'mypassword'@'localhost' (using password: YES)

and this is mysql_connect order:

$con=mysql_connect('localhost',$password,$username) or die(mysql_error());

How to solve it?

and How to work on localhost to don't have problem with host and server?

thanks

3

2 Answers 2

1

So to make it an answer:

The correct order for the params is. see here

$host, $username, $password

so i guess you mixed it up.

and make sure that your server is listening on localhost mine for exapmle is listening to mysql.mydomain.com

and as @Jay Blanchard pointed out the mysql_* functions are deprecated. so better don't use them.

0

"localhost" is the machine where you're running the code. For that to work, you need to

  1. you are using the correct argument ordering as per https://www.php.net/manual/en/function.mysql-connect.php
  2. you have MySQL running on the same machine this code runs and
  3. you are using a username and password combination that has connection permissions.

Not all of these are the case right now.

As an additional note, the mysql_... functions are considered dangerous and have been replaced with mysqli_... equivalents (note the i in there), which have a different argument ordering (so you can't accidentally use mysql_... functions as a typo by forgetting that i) and should be used instead. Especially if your host has an up to date PHP version, the msql_... function calls will plain not work and cause errors that wouldn't solve by shuffling arguments around.

2
  • The problem is almost certainly that he reversed $username and $password as per @Le_Morri's comment.
    – Eric J.
    Sep 24, 2014 at 16:00
  • indeed, and he'd find that out by running through step 1. We've all seen too many questions where even after step 1, it turns out steps 2 and 3 are still necessary though, so adding them to the answer just in case is cheap and effective. Sep 24, 2014 at 16:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.