SSL Yii connection to postgresql Google cloud database - php

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!

Since the DB is not on your machine there is no need for you to have PostgreSQL installed and this is the reason (I think) that these constants are not recognised. Try this:
'attributes' => [
'sslmode' => 'verify-ca',
'sslkey' => 'path/to/my/client-key.pem',
'sslcert' => 'path/to/my/client-cert.pem',
'sslrootcert' => 'path/to/my/server-ca.pem',
],

Related

Typo3 with MSSQL [duplicate]

I tried to install TYPO3 (8.7.7) on my Webserver (IIS) and I'd like to use my SQL Server instead of MySQL.
I found lots of instructions how to make this (on typo3.org and other websites) but none of these worked for me.
I found out, that I must install two extensions before I start the installation (ADOdb & DBAL). Probably there is my fault.
Can anybody explain step by step how to install these extensions before the TYPO3 installation?
I'm using the following configuration to successfully run TYPO3 on SQL Server on my local windows machine:
'DB' => [
'Connections' => [
'Default' => [
'charset' => 'utf-8',
'dbname' => 't3',
'driver' => 'sqlsrv',
'host' => 'localhost',
'password' => 'yourPassword',
'port' => 1433,
'user' => 'sa',
],
],
],
It's a bit complicated to set up with the installer as it is not yet "clickable". What you can do is call the install script and when it's asking you to configure the database connection you go to your file system and manually add the config section above (with your connection params of course) in the LocalConfiguration.php file.
Then reload the installer - which should now recognize the configured database connection and let you go to the last step where you can import / create the base tables and data.
Note: At the moment I know of two bigger areas where SQL Server is still a problem with TYPO3 8.7 - that's workspaces and database compare. The last one means that after you have existing data in your SQL Server tables won't let you alter them via the TYPO3 database compare tool - you have to change tables manually if you need to.
Find a gist of the table create statements on https://gist.github.com/psychomieze/9570ea1f578aee7a1fbb68c3240a21c8
With 8.7, Doctrine DBAL has been integrated into the core and ADOdb & DBAL sysexts have been removed as there is no need anymore.
Take a look at the documentation of Doctrine DBAL http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html and it should fit perfectly to the configuration of the DB in `LocalConfiguration.php``
'DB' => [
'Connections' => [
'Default' => [
'charset' => 'utf8',
'dbname' => 'typo3',
'driver' => 'mysqli',
'host' => 'mysql',
'password' => 'dev',
'port' => 3306,
'user' => 'root',
],
],
],
Now my Typo3 is working.
I solved my problem a little bit complicated.
I made a test environment and installed Typo3 with MySQL.
Then I copied the database with the "Microsoft SQL Server Migration Assistant 7.6 for MySQL"
(https://www.microsoft.com/en-us/download/details.aspx?id=54257) to my main environment.
After that I copied all the created folders (typo3conf, typo3temp etc.) to my main environment
and edited the databaseconnection in the LocalConfiguration.php file like Georg Ringer proposed.
When I am installing Typo3 and MSSQL next time I will do it like susi proposed.
Thanks for your help.

How do I make my Laravel project on Heroku use Heroku Postgres?

I have been working on a project that requires I set it up in Heroku. The Database I have been using thus far locally is mySQL, but I am looking to use Postgre when the project is on Heroku.
I have done a large amount of searching but have yet to find an answer as to how I configure my Laravel project to use Postgres and how do I perform basic functions such as adding a new database to Postgres.
If there is an alternative way to just use mySQL as is that would be great.
Thanks for the help.
Heroku places (once you provision a Heroku Postgres instance) the database credentials in the DATABASE_URL environment variable, in the following format:
postgres://username:password#hostname:port/database
Now, you could manually fill out your DB_HOST, DB_USERNAME, etc. .env vars from this, but there's a better way: you can parse the URL in your config/database.php file.
Note: Newer versions of Laravel now support a DATABASE_URL .env value directly. No need to parse anymore.
'pgsql' => [
'driver' => 'pgsql',
'host' => parse_url(env('DATABASE_URL'), PHP_URL_HOST),
'port' => parse_url(env('DATABASE_URL'), PHP_URL_PORT),
'database' => ltrim(parse_url(env('DATABASE_URL'), PHP_URL_PATH), '/'),
'username' => parse_url(env('DATABASE_URL'), PHP_URL_USER),
'password' => parse_url(env('DATABASE_URL'), PHP_URL_PASS),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
(Make sure you set DB_CONNECTION to pgsql so this connection is used!)
how do I perform basic functions such as adding a new database to Postgres
You don't. A Heroku Postgres instance comes with one database.

Configuration of Yii2 oci8 module

i am trying to connect my Yii2 project to Oracle db, i have found this oci8 plugin for yii2 written by apaoww on github. I managed to get php oci8 extension working, and encountered i hope my last problem with the connection.
I know dbname, ip, username, password and port to connect on, but still i was not able to decrypt, where the schemaname belongs to, i probably am a complete dumba**, but i was not able to find any other examples of filling the dp.php config file, than the one on GitHub project page, which didn't really make it clear for me. My issue is, where should i put the schemaname in this array?
'db' => [
'class' => 'apaoww\oci8\Oci8DbConnection',
'dsn' => 'oci8:dbname=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SID=xe)));charset=AL32UTF8;',
'username' => 'yourdatabaseschemaname',
'password' => 'databasepassword',
'attributes' => []
],

Error while trying to connect to an external DB server from Google App Engine

I have a scenario where for a certain reason I cannot use Google's Cloud SQL. Hence I want the application at appid.appspot.com to connect to an external DB server.
DB.php
'hostname' => '202.202.202.202',
'username' => 'user',
'password' => 'password',
'database' => 'dbname',
'dbdriver' => 'mysql',
This gives me a Server Error, however I'm able to connect to the database from mysql workbench. This application does not have a problem while connecting to Cloud SQL.
Error message:
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
Can someone help me understand where I'm going wrong.
I did the following changes and got it working.
Instead of IP address I gave the external DB server a hostname.
'hostname' => 'dbserver.example.com',
'username' => 'user',
'password' => 'password',
'database' => 'dbname',
'dbdriver' => 'mysqli',
Then I activated billing for the Google App Engine project. Once you activate billing the Google Socket API will start functioning.
Please do not try immediately. Give it sometime and this should start working just fine.

Can't connect to database with laravel 5

I'm trying to connect to my mssql database with laravel 5 but it's not working. I've tried to connect with different mssql databases so it's not a firewall issue. Also my credentials are correct. I found on google that you need SQL Server Native Client 11.0 and I've already installed that.
This is my connection array in config/database.php:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('nvt'),
'database' => env('nvt'),
'username' => env('nvt'),
'password' => env('nvt'),
'charset' => 'utf8',
'prefix' => '',
],
And I've set the default to "sqlsrv" :
'default' => env('sqlsrv','sqlsrv'),
But when I'm trying to create a table I receive the error:
PDOException in Connector.php line 50: could not find driver
What could be wrong???
EDIT:
I've installed pdo for sqlsrv from here:
http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
And I added it to my php.ini file:
extension=\Installaties\php_pdo_sqlsrv_53_nts.dll
But stil I receive the error?
Try to remove the eve() method, i mean use the following method
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => 'nvt',
'database' => 'nvt',
'username' => 'nvt',
'password' => 'nvt',
'charset' => 'utf8',
'prefix' => '',
],
I ran into a similar issue. Try putting in the server info directly rather than using env. If it works, then you know Laravel is having an issue reading the .env file.
I encountered your problem the last time I tried my connection in sqlsrv. I am using xampp. Try putting yung php_pdo_sqlsrv_53_nts.dll in the ext folder, replace extension=\Installaties\php_pdo_sqlsrv_53_nts.dll with extension=php_pdo_sqlsrv_53_nts.dll and try installing odbc 11 on your computer. It worked for me but not sure why. (not an expert) if it worked good to help a fellow person and if not, sorry for the trouble. Thank you for the time reading.
You may try any of the following solutions
Check that you have entered the right connection parameters. Test by connecting to the DB with a client tool.
Make sure you have the right version of sqlsrv configured for your machine. Check the PHP logs to be sure your web server was able to load the extension correctly.
Set the port to null in your env file
As a tip, I won't advise anyone to set the connection parameters anywhere but in the .env (Setting it in config/database is a security risk).

Categories