2
votes

how to connect cpanel db from Localhost. i know connect from localhost. But i need to connect from server. i am trying like this

<?php
mysql_connect("208.91.199.141","username","password") or die(mysql_error());
mysql_select_db("db");
?>

i get an Error

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'glansade'@'49.206.54.187' (using password: YES) in C:\xampp\htdocs\calendar\db_server.php on line 2 Access denied for user 'glansade'@'49.206.54.187' (using password: YES).

How to solve this....? Please Help me. Thanks

3
Are you sure...you are using the right credentials with correct privileges set for the user ??swapnesh
yes. i given correct username and password. but i dont know what is the problem..?user2637639
Do you create a user with previlage to acces from your php server?May be your ip address is not added for mysql userShijin TR
If you're just learning PHP, please, do not learn the obsolete mysql_query interface. It's awful and is being removed in future versions of PHP. A modern replacement like PDO is not hard to learn. A guide like PHP The Right Way can help explain best practices. Always be absolutely sure your user parameters are properly escaped or you will have severe SQL injection bugs.tadman

3 Answers

3
votes

Go to RemoteMysql from cpanel

you have to add %.%.

Then you will be able to connect from remote Db.

0
votes

You will not want to add %.% to Remote Database Access Hosts as it is a security concern. The %.% is a wildcard and using that wildcard in access hosts like that will expose mysql to the internet and the possibility of unauthorized database access is greatly increased.

Based on your error, the IP you are connecting from is 49.206.54.187. You will want to use this IP address in Remote Database Access Hosts. If you do not know the IP address to use, you can check your IP at http://cpanel.net/myip

I also see that you are connecting with your cPanel account username. While this should work, it is the preference of many to setup a separate account for each Database. To accomplish this, follow these instructions.

  • In cPanel, select MySQL Databases
  • In the Databases section, under "MySQL Users", create a New MySQL user.
  • After creating that user, add that user to the Database in the section "Add User To Database"
  • Make sure to select all privileges.

Thanks!

-3
votes

I'm not an expert, but I think you should try :

mysql_connect("localhost","username","password") or die(mysql_error());

Instead of :

mysql_connect("208.91.199.141","username","password") or die(mysql_error());