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());
}
?>
-
5Because access is denied for that user.Oliver Charlesworth– Oliver Charlesworth2012年01月22日 18:31:43 +00:00Commented Jan 22, 2012 at 18:31
-
@OliCharlesworth I'd like to give +10 for that comment :)TimWolla– TimWolla2012年01月22日 18:32:42 +00:00Commented Jan 22, 2012 at 18:32
-
@@OliCharlesworth, so there is no user with that name ?user1161867– user11618672012年01月22日 18:34:05 +00:00Commented Jan 22, 2012 at 18:34
-
@OliCharlesworth But i can access cpanel with that username and password.user1161867– user11618672012年01月22日 18:34:52 +00:00Commented 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/1066828Fahim Parkar– Fahim Parkar2012年01月22日 18:37:21 +00:00Commented Jan 22, 2012 at 18:37
5 Answers 5
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.
2 Comments
You cannot access to the database because your usename + password aren't correct.
1 Comment
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
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
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.