1
votes

I have an application written in C# and it does connect with the database.

Here's the error I'm getting:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'username'@'localhost' (using password: YES) in (php file) on line 15 Could not connect: Access denied for user 'username'@'localhost' (using password: YES)

Here is my code:

$mysql = mysql_connect("localhost", "username", "password");
if (!$mysql) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

I got this example from:

http://php.net/manual/en/function.mysql-connect.php

What am I doing wrong?

1
If you're just starting, I recommend you learn MySQLi or PDO instead. MySQL is deprecated and is soon to be removed.Amal Murali
are you sure that your username=username and password=password in mysql?ABorty
How about giving us the error mysql_error is printing?Reinherd
check the username and password is correctSundar
@Sundar nvm I will be using Mysqli. Thanks anyway!Loko

1 Answers

1
votes

Your username in mysql in probably not "username", as your password is not "password". Please change it to something like

 $mysql = mysql_connect("localhost", $username, $password);

where $username is variable with your db username and $password is variable with your db password.

Also it would be good thing to use MySQLi instead of mysql_ functions.