Question:
what is the error in the code below? it works fine in computer. but not in my website. why?
as
2008-10-02 02:20:05 UTC
this is the code:

$con = mysql_connect("localhost","un","pw");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db", $con);


this is the error message:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'un'@'localhost' (using password: YES) in /home/public_html/softwares.php on line 47

code in line 47 is mentioned above.
please help.
Five answers:
DiggyK
2008-10-02 02:23:29 UTC
This is an access denied error which means exactly what it implies: the use 'un', connection to 'localhost' with a password was denied access to the database. When you tried on your computer, you probably were connecting to your own database on your workstation and now you're trying to connect to the db on the server, but the server isn't setup to allow that user to connect with that password.
rijosjcet
2008-10-02 09:35:59 UTC
You have to provide the exact ip address or DNS name in the line '$con = mysql_connect("localhost","un","pw");' instead of "localhost" with appropriate username and password..... try the ebooks at http://www.techiesoft.net/ebooks.html to know more about it
connoisseur
2008-10-02 09:27:17 UTC
i agree with diggyk. if ur using something like apache tomcat then u need to configure it to be able to connect to the host database.



i had the same problem. i made a new user and password and configured the webserver to that user and passwd. this way only the database was accessed and all the other files were not accessable
bob b
2008-10-02 09:37:08 UTC
Check your user name and password is correct.



you user name may like



database name_username



....and your database name maybe in a similar context.
MaKoY LaBz
2008-10-02 09:42:49 UTC
instead of localhost use your ip address

eg.. $con = mysql_connect("192.168.0.1","un","pw");



that would solve the problem


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...