0

When i upload db.php page to the server it's say

Warning: mysql_connect() [function.mysql-connect]: Access denied for user     
'somename'@'somenumber' (using password: YES) in /home/somename/public_html/db/db.php on 
line 2 Could not connect to Server: Access denied for user 'somename'@'somenumber' 
(using password: YES)

Why it's say ?

db.php code:

<?php   
$db = mysql_connect('www.mysite.com', 'somename', 'password'); 
if (!$db)         
{
die('Could not connect to Server: ' . mysql_error());
}
if (!mysql_select_db("datbasename",$db))
{
die('Could not connect to DataBase : ' . mysql_error());
}
?>
5
  • 5
    Because access is denied for that user. Commented Jan 22, 2012 at 18:31
  • @OliCharlesworth I'd like to give +10 for that comment :) Commented Jan 22, 2012 at 18:32
  • @@OliCharlesworth, so there is no user with that name ? Commented Jan 22, 2012 at 18:34
  • @OliCharlesworth But i can access cpanel with that username and password. Commented Jan 22, 2012 at 18:34
  • I don't know PHP much, but can you see how here connection is made... stackoverflow.com/a/8951736/1066828 Commented Jan 22, 2012 at 18:37

5 Answers 5

1

In mysql it' not only username and password, but also host that matters while connecting.

Your username and password may work for localhost but to connect from host1.someserver.com you will need different credentials.

In your case @'somenumber' may be IP address that you are connecting from, ensure that username you are using is allowed to connect from this IP.

Sign up to request clarification or add additional context in comments.

2 Comments

well, @dev-null-dweller, But i can access with that username and password. so that i use in db.php code: Host= www.mysite.com, Username= myusername and password= password. But Error..!!
You can acces your database from one host, but as i said this credentials may not work when connecting from other hosts. Instead of blindly trying to connect, contact your hosting provider to get more help.
0

You cannot access to the database because your usename + password aren't correct.

1 Comment

But i can access cpanel with that username and password.
0

line 2 Could not connect to Server: Access denied for user 'somename'@'somenumber' says CLEARLY, access is denied for the user somename. Get privileges to get connected first...

Good Luck!!!

Comments

0

Either the password is wrong or you don't have enough privileges for the user.

Try with username as "root" and password as "" and see if it works, otherwise you are doing it wrong.

2 Comments

Well, @sh4nx0r i'm trying this.
it's say access denied for user 'root'
0

In mysql_connect('www.mysite.com', 'somename', 'password');

you will need to give your database hostname, not your site hostname.

Check with your hosting provider for database hostname.

It is localhost if database is on same server/machine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.