Where do you put the connection settings for a database connection (things like host, dbname, user, password)? Is it placed in the database class or file, or outside in a config file, or somewhere else?
For PostgreSQL, I really like to use pg_service.conf
. It allows me to put all connection specific settings (hostname, database name, username, password, etc) into ~/.pg_service.conf
or to /etc/postgresql-common/pg_service.conf
and give them common name (service name).
Now, any program (Perl, PHP, etc) that wants to connect to database can simply specify "service=name"
as their connection string - nice, clean, secure and easily maintainable.
As far as I know, MySQL has similar mechanism for ~/my.cnf
or /etc/my.cnf
files - you may want to look into that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With