3

I am making simple mysqli connection to my database on Godaddy windows hosting, my code is as follows :

<?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 granted username and password as well as the database name, all my credentials are proper, though 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 same database name and credentials using wamp server, I am not much into IIS server and windows hosting.. Any help will be appreciated.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Khaldoun
  • 49
  • 1
  • 1
  • 4
  • check with godaddy support that mysqli extendion installed in your hosting panel – Shehary Jul 18 '15 at 17:46
  • It is installed, i check phpinfo() – Khaldoun Jul 18 '15 at 17:48
  • Just making sure: is index.php hosted on your remote server or are you executing it on your own machine ? – spenibus Jul 18 '15 at 17:55
  • It is hosted @spenibus, I have other files on the same hosting, `http://greencool.co/green_cool_final/products/` is the page with problem, `http://greencool.co/green_cool_final/index/` is a working page...I also tried connection through PDO and `mysql_connect` I am still getting the same results. – Khaldoun Jul 18 '15 at 17:59
  • It's not much but have a look here: http://stackoverflow.com/a/16175657/3512867 – spenibus Jul 18 '15 at 18:05
  • Alright @spenibus, I will get back to you, I was hoping from something to be resolved with some configuration file through FTP or so, I will try what is stated in the question and what Sjon has stated and get back to you as soon as my client provides me access to the server, thanks for your help. – Khaldoun Jul 18 '15 at 18:12

3 Answers3

6

I once had this problem and simply resolved it by setting the real IP address of the database server in my host when connecting to the database. To get the IP address, log into your hosting account and access the databases, then click on managing the database you want, this will take you to phpMyAdmin. To the right there is a block with title Database Server, you can find the server IP address in the first list item. Use it in your $host rather than 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 the support and got this reply :

Joshua - I think the permissions are the cause of the issue. Once you have them properly updated, the problem should go away.

They stated that the files permission could be the issue, I updated the file permissions but didn't resolve it.

Sometimes the solution is much closer than you can think of!!

KAD
  • 10,972
  • 4
  • 31
  • 73
1

The new MySQL database setup form will accept mixed case characters as the database name/username, it will silently convert them to lowercase on you. The phpMyAdmin login, then, is case sensitive, so you may want to copy and paste from the Control Center into phpMyAdmin to be sure you’re feeding it the correct username.

Shehary
  • 9,926
  • 10
  • 42
  • 71
0

It's a bit of a stab in the dark; but you should check the actual host that's defined in mysql's user table. It's possible your WAMP solution connected to localhost through ipv4 (127.0.0.1); and your current server uses ipv6 (::1). The user that you use to connect should have the same address defined in the database-server. The simples method of checking this is making sure 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 hostname (eg. localhost)

Sjon
  • 4,989
  • 6
  • 28
  • 46
  • I have defined my user through godaddy database user creation, I did not import any users that are created on localhost, but I will verify your point @Sjon and get back with results once I have them.. – Khaldoun Jul 18 '15 at 18:04