Welcome Guest, Not a member yet? Register   Sign In
database.default.dsn not working
#1

hello, I am trying to connect to postresql using the dsn parameter for the default database schema
I have confirmed the pdo_pgsql is enabled in phpinfo, ultimately I need to be able to add sslverify to the dsn string to make an SSL only connection to the postgresql database
here is my dsn - no connection, does not work
database.default.dsn ='pgsql:host=xx.xx.xx.xx;port=5432;dbname=xx;username=xxx;password=xxxx;sslmode=verify-ca;sslrootcert=/ssl/db/server-ca.pem;sslcert=/ssl/db/client-cert.pem;sslkey=/ssl/db/client-key.pem'
#database.default.hostname = ip
#database.default.database = dbname
#database.default.username = dbuser
#database.default.password = dbpass
#database.default.DBDriver = Postgre
#database.default.port = 5432
#database.default.schema = public


if I un comment the below - this works
#database.default.dsn ='pgsql:host=xx.xx.xx.xx;port=5432;dbname=xx;username=xxx;password=xxxx'
database.default.hostname = ip
database.default.database = dbname
database.default.username = dbuser
database.default.password = dbpass
database.default.DBDriver = Postgre
database.default.port = 5432


I have been referencing the following database configuration page on codeigniter user guide
https://codeigniter.com/user_guide/datab...h-env-file
any help or guidance would be greatly appreciated
Reply
#2

CI4 does not use the PDO driver.
To use a DSN for CI drivers, the string must follow the format: DBDriver://username:password@hostname:port/database
But in your case, your DSN should work specifying the driver through a property.

database.default.DBDriver = Postgre
Reply
#3

(02-05-2022, 11:29 AM)iRedds Wrote: CI4 does not use the PDO driver.
To use a DSN for CI drivers, the string must follow the format:  DBDriver://username:password@hostname:port/database
But in your case, your DSN should work specifying the driver through a property.

database.default.DBDriver = Postgre

Thank for you for the response. 

I am able to successfully connect to the database with mysql or postgre the issue comes when I want to use an SSL connection, it does not work. 

I can connect using the command line and the certificates but not through the .env file or the database.php file
Reply
#4

Try to create a database connection.
PHP Code:
pg_connect('host=xx.xx.xx.xx port=5432 dbname=xx username=xxx password=xxxx sslmode=verify-ca sslrootcert=/ssl/db/server-ca.pem sslcert=/ssl/db/client-cert.pem sslkey=/ssl/db/client-key.pem'); 

If the connection failed or without SSL, then you can not read further.

If the connection succeeded.
PHP Code:
database.default.DSN ='pgsql:host=xx.xx.xx.xx;port=5432;dbname=xx;username=xxx;password=xxxx;sslmode=verify-ca;sslrootcert=/ssl/db/server-ca.pem;sslcert=/ssl/db/client-cert.pem;sslkey=/ssl/db/client-key.pem'
database.default.DBDriver Postgre 
Note that DSN !== dsn. Case sensitive parameter.
Reply
#5

thank you very much for your help. 

The below finally worked in the .env file

database.default.DSN = 'pgsql:host=xx.xx.xx.xx;port=5432;dbname=xxx;user=xxx;password=xxxx;sslmode=verify-ca;sslrootcert=/ssl/db/pg_server-ca.pem;sslcert=/ssl/db/pg_client-cert.pem;sslkey=/ssl/db/pg_client-key.pem'

database.default.DBDriver = Postgre
Note username is not a valid parameter, it is user
https://www.php.net/manual/en/function.pg-connect.php
Reply
#6

(This post was last modified: 07-08-2022, 03:47 AM by FilembarEliJeevan.)

When we set a value for the variable "database.default.dsn" in the.env file we should not get the error "Unable to connect to the database" and we should be able to connect to the echatrandom echat database.

Context

OS: php:7.4-fpm
Web server : Docker image httpd:2.4
PHP : 7.4
Reply




Theme © iAndrew 2016 - Forum software by © MyBB