-1

So I'm trying to connect remotely to a database hosted on godaddy. I'm getting a 1045 error everytime. During troubleshooting I went back to my code hosted locally and tried changing the hostname from "localhost" to the servers ip address... this resulted in 1045 error as well. I've verified that the ip address is indeed correct. The database is hosted on a godaddy shared hosting account. I've ran thru all the troubleshooting with them and they can't get me a hostname that will work leaving me to believe the issue is with the mysql or cpanel user only being assigned to "localhost". Any ideas on how to resolve this? The first line of code works, the second does not.

$db = new PDO('mysql:host=localhost;port=3306;dbname=name;charset=UTF8', 'user', 'pw', array(PDO::ATTR_EMULATE_PREPARES => false));

$db = new PDO('mysql:host=100.100.100.1;port=3306;dbname=name;charset=UTF8', 'user', 'pw', array(PDO::ATTR_EMULATE_PREPARES => false));
  • Do post the code you're using to connect so we don't have to guess what you're doing. Normally 1045 means you're using the wrong credentials. – tadman Sep 21 '17 at 20:42
  • Error 1045 has nothing to do with your hostname. Either your supplied username, or your supplied password is wrong. Please tell me you are not trying to log in with root, and that you have created a user account in your database that can access the tables? – GrumpyCrouton Sep 21 '17 at 20:44
  • That's my point, the username and password work fine when hostname is localhost. When host is the ip address instead it gives a 1045 – River city Phoenix Sep 21 '17 at 20:47
  • post edited to show working code vs non working – River city Phoenix Sep 21 '17 at 20:49
  • And what does the auth tables of the mysql server say about remote connections using that very username? – mario Sep 21 '17 at 20:49
  • I don't have access to those tables... it's a godaddy shared hosting account. – River city Phoenix Sep 21 '17 at 20:50

1 Answers1

-1

Remove port number second line of code, the port number can be different on remote MySQL. Also make sure you host-name you're using for remote is alive. Try to ping it. Also, make sure you have error handling for connection like below:

  try{
    //Your second line will go here
   } catch(PDOException $e){ //Catch any errors
        //$this->error = $e->getCode(). '-'. $e->getMessage();
        echo "Could not connect to database: " . $e->getMessage()."\n";
    }

I hope it will work, I don't see any issue there.

slon
  • 936
  • 1
  • 7
  • 12
  • If the port number is different from the default 3306, then removing it will hardly make things better. Maybe you should suggest that they check the post number using the GoDaddy admin panel – RiggsFolly Sep 21 '17 at 23:27
  • I am strongly suggesting to check the following things: Check database name, username, password, port number (if he wants to have in in that string). In General, to check everything what he did to create database on remote and user to that database. The error "1045 error" you get from MySQL when you're refused from access. – slon Sep 22 '17 at 15:57