To set the PostgreSQL DB connection, schema parameter is not to be included
1 2 3 4 5 |
$Conn = new PDO('pgsql:host=localhost;port=5432;dbname=db', 'user', 'pass'); $result = $Conn->exec('SET search_path TO accountschema'); if ( ! $result) { die('Failed to set schema: ' . $Conn->errorMsg()); } |
Is this a good practice? Is there a better way to do this?
In order to specify the default schema you should set the search_path instead.
1 |
$Conn->exec('SET search_path TO accountschema'); |
You can also set the default search_path per database user and in that case the above statement becomes redundant.
1 |
ALTER USER user SET search_path TO accountschema; |