Skip to content

Commit

Permalink
add charset option for pdo_pgsql driver
Browse files Browse the repository at this point in the history
add charset option for pdo_pgsql driver
  • Loading branch information
deeky666 committed Dec 18, 2013
1 parent c504375 commit 36fa410
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ pdo\_pgsql
- ``host`` (string): Hostname of the database to connect to.
- ``port`` (integer): Port of the database to connect to.
- ``dbname`` (string): Name of the database/schema to connect to.
- ``charset`` (string): The charset used when connecting to the
database.
- ``sslmode`` (string): Determines whether or with what priority
a SSL TCP/IP connection will be negotiated with the server.
See the list of available modes:
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ private function _constructPdoDsn(array $params)
$dsn .= 'dbname=' . $params['dbname'] . ' ';
}

if (isset($params['charset'])) {
$dsn .= "options='--client_encoding=" . $params['charset'] . "'";
}

if (isset($params['sslmode'])) {
$dsn .= 'sslmode=' . $params['sslmode'] . ' ';
}
Expand Down

7 comments on commit 36fa410

@adgeese
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gentlemen, when using the charset string with pgbouncer we are given an error:

2014-06-11 14:47:11.061 319 WARNING C-0x1071580: (nodb)/(nouser)@127.0.0.1:34024 unsupported startup parameter: options=--client_encoding=UTF8
2014-06-11 14:47:11.061 319 LOG C-0x1071580: (nodb)/(nouser)@127.0.0.1:34024 closing because: Unsupported startup parameter: options (age=0)
2014-06-11 14:47:11.061 319 WARNING C-0x1071580: (nodb)/(nouser)@127.0.0.1:34024 Pooler Error: Unsupported startup parameter: options

In order to fix this issue with pgbouncer, we would require the '--client_encoding=' argument to be set to 'client_encoding.'

@Ocramius
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rocksfrow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adgeese have you reported an issue for this?
@Ocramius I too am experiencing this issue -- it's definitely a problem with pgbouncer.

pgbouncer doesn't like that option format -- this is not a pgbouncer bug but indeed a dbal issue.

Here is a very similar issue/pull request from node.js's pgsql driver resolving the exact same issue:
brianc/node-postgres#356

@rocksfrow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renders DBAL unusable with pgbouncer -- I am forced to downgrade.

@rocksfrow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius this is the exact same change that needs to be made:

Hebo/node-postgres@323a2f9

I'll see if I can find a bug report -- if not maybe I can create a pull request.

@rocksfrow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just confirmed the fix works locally... IE, passing the client_encoding parameter directly rather than through the 'options' parameter

@rocksfrow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius I confirmed a bug report was never filed. I've fixed the bug and filed a pull request.

#823

Please sign in to comment.