I’m newbie user of Yii and I need to connect my Yii2 application to a Google cloud database (postgres). I need to made the connection using the SSL certificates I already have. I have all the credentials (host, user, 3x ssl, etc).
The thing is I’m able to connect to this remote google database using both PgAdmin client and the Google SDK console (Google Shell), but I can’t connect my Yii2 application to this database. I read a lot of documentation and found nothing.
This is what I have in my common/config/main-local.php (Yii2 advanced configuration), I added the field 'attributes', just in case it works, but as I thought is not working:
'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'pgsql:host=my-host;dbname=my-db-name', 'attributes' => [ PDO::PGSQL_ATTR_SSL_KEY => 'path/to/my/client-key.pem', PDO::PGSQL_ATTR_SSL_CERT => 'path/to/my/client-cert.pem', PDO::PGSQL_ATTR_SSL_CA => 'path/to/my/server-ca.pem', ], 'username' => 'myusername', 'password' => 'mypassword', 'charset' => 'utf8', ],
This is how I connect through Google Shell, this works:
psql "sslmode=verify-ca sslrootcert=path/to/my/server-ca.pem sslcert=path/to/my/client-cert.pem sslkey=path/to/my/client-key.pem hostaddr=google-instance-host user=david.tamarit dbname=google-db-name"`
Then, I put my password and I'm connected to my database in Google shell.
- In PgAdmin, I pass my credentials and I connect to the database, this works too.
How can I connect to my google cloud database using Yii?
Thanks in advance!