Access denied for user while connecting to godaddy database on windows hosting?

I am doing a simple communication mysqli

to my database on the go Godaddy, my code looks like this:

<?php 

        error_reporting(E_ALL & ~(E_STRICT|E_NOTICE));

            $host = 'localhost'; 
            $user = 'root_user_name'; 
            $password = 'root_user_pass'; 
            $db = 'my_database'; 
            $cxn = mysqli_connect($host,$user,$password) or 
                     die(mysqli_connect_error()); // <<<<<< line 9
            mysqli_select_db($cxn, $db ) or die(mysqli_connect_error()); 


        die('test');

      

I am sure of the username and password provided, and the database name, all my credentials are correct, although I am getting this error:

Warning: mysqli_connect (): (HY000 / 1045): access denied for user 'root_user_name' @ 'localhost' (using password: YES) in G: \ path \ to \ file \ index.php on line 9 Access denied for user 'root_user_name' @ 'localhost' (using password: YES)

I got this working on localhost with the same database name and credentials using a Wamp server, I don't really like IIS server and Windows hosting. Any help would be appreciated.

+3


source to share


3 answers


I had this problem and just solved it by setting the real IP of the database server on my host when connecting to the database. To get the IP address, login to your hosting account and access the databases, then click on manage the database you want and this will take you to phpMyAdmin. On the right is a block titled Database Server , you can find the server's IP address in the first item of the list. Use it on $host

, not on localhost:

 $host = '51.51.51.51'; // <<<< just a fake IP address for the example

      

I had a lot of harsh time to find out what was going wrong, I even contacted support and got this answer:



Joshua - I think the permissions are causing the problem. Once you update them, the problem should go away.

They stated that the file problem might be the problem, I updated the file permissions but didn't resolve it.

Sometimes the solution is much closer than you might imagine!

+6


source


The new MySQL database setup form will accept mixed case characters as the database name / name, it will convert them to lower case without any problem. This way the phpMyAdmin login is case sensitive, so you can copy and paste it from Control Center to phpMyAdmin to make sure you entered the correct username.



+1


source


It's a bit of a kick in the dark; but you have to check the actual host

defined in the mysql users table. Perhaps your WAMP solution connected to localhost via ipv4 ( 127.0.0.1

); and your current server is using ipv6 ( ::1

). The user you are using to connect must have the same address defined on the database server. A simple method to check this means you have 3 users in your db with these credentials, one for ipv4 ( 127.0.0.1

), one for ipv6 ( ::1

) and one based on the hostname (for example localhost

)

0


source







All Articles