Where would I be able to pass my client certificates to connect to a PostgreSQL database? Do I have to pass these certificates in the dsn
or options
parameters in the PDO constructor? I'm unable to find any documentation online.
I am using PHP 7.0.22 on a Ubuntu 16.04.1. I have SSL support enabled for the pgsql driver. I did find these constants in the PDO class: PDO::MYSQL_ATTR_SSL_CA
, PDO::MYSQL_ATTR_SSL_KEY
and a few others, but these are obviously for mySQL and not PGSQL.
EDIT
Here is a working secure implementation based on the answer below:
$dbh = new PDO('pgsql:localhost=host;port=26257;dbname=bank;sslmode=require;sslcert=[path]/client.maxroach.crt;sslkey=[path]/client.maxroach.key;sslrootcert=[path]/ca.crt;',
'maxroach', null, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => true,
));