We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Can't connect to remote mysql DB

Hello,

I'm having trouble connecting to a remote mysql DB. I'm using a RDS instance in Amazon for this connection. I believe the issue is that my "host" config is not being recognized and the connection resets to the default "localhost". That's why I'm getting the error "SQLSTATE[HY000] [1045] Access denied for user 'username'@'server_ip (using password: YES)" where server_ip is the ip of the application server.

For my connection I'm using this piece of code in my public/index.php

    $di->setShared('db', function () {
        return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
            "host" => $this->get("config")->database->host,
            "username" => $this->get("config")->database->username,
            "password" => $this->get("config")->database->password,
            "dbname" => $this->get("config")->database->dbname,
            "port" => $this->get("config")->database->port,
            "options" => [
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
                PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
                PDO::ATTR_CASE => PDO::CASE_LOWER
            ]
        ));
    });

The connection to the db works because I tested it using PDO directly so it's obviously a problem with my Phalcon connection. I'm using the Ini adapter for the config and I've removed all leading spaces before the "=" operator.

Thanks in advance.



85.5k

its not a phalcon adapter problem for sure.

Phalcon adapter uses PDO, so its the same thing, also your errors means somethning else. nothing do to with the connection.

give access to the mysql user from that host, that probably what the problem is

As @Izo said, allow remote access or set permisions.

If you do not have control over this, ask your hosting provider. Some companies grant remote access only on demand (as it should be) :)