Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a website hosted at godaddy (say "abc.co.in"). After having logged into cpanel through my cpanel id and password (say "siteid" and "sitepw" respectively), i went ahead and created a MySQL Database named "myDb". Now i assigned a user to that database and granted all privileges. Say my database user id and password are "dbUser" and "dbPw" respectively.

Now i want to Add a table to this database using php.. However, upon connecting, using the following code:

$con=mysqli_connect("abc.co.in","dbUser","dbPw","myDb");

i get an error :

Warning:mysqli_connect():(HY000/1045) - Access denied for user 'dbUser'@'xxx.xxx.x.xxx' (using password: YES)"

Now i read somewhere that my user name needs to be of the format "cpanel-username_mysql-username", i.e., in this case: "siteid_dbUser", whilst password still sticking to the database password. However, It still returns me the same error message.

Am i typing the first parameter, 'hostname' incorrect? It doesn't need to be "localhost", does it?
Kindly help for i am gravely confused. I know it might seem like a repetitive question but i checked a lot of posts here but couldn't find a solution..
Thanks in advance!

--EDIT--
Just for the record, the php file in which i'm trying to establish the connection and trying to add a table to my database is a local php file running on localhost. Just thought i'd mention it, incase it makes a difference.

--EDIT 2--
Okay so according to THIS link, even my database name needs to change.. hence modifying my code to

$con=mysqli_connect("abc.co.in","siteid_dbUser","dbPw","siteid_myDb");

I tried it out but all in vain.. Still the same error message. I even changed the host to "localhost" and tried the same but it just doesn't connect.

share|improve this question
1  
The password is probably wrong. –  FDL Jun 25 at 12:33
    
nah, I double checked it.. The password is same as the User's password assigned to the database.. What i don't get is do i not need to somewhere provide my cpanel password too? if so, where?? –  Aldo Jun 25 at 12:36
    
make sure that the user you created for mysql has the correct IP associated with it. If, for example, you created the user connecting as localhost, it will not work if you are trying to connect via 192.168.1.X. It might not even work with 127.0.0.1 –  Russell Uhl Jun 25 at 12:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.