Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Added optional charset to pdo dsn #5064

wants to merge 2 commits into from

3 participants


It was not possible to set the charset of the connection, now it can be passed as configuration parameter.

If somebody could give me a hint how - I'll also write a test :)


The correct place to add a test for this would be ./tests/ZendTest/Db/Adapter/Driver/Pdo/ConnectionTest.php.

Unfortunately, it looks like there's not really any existing tests for this class for you to reference. Also, the way the connect() method is written doesn't allow for testing the DSN string building without actually invoking a real database connection, so writing a clean test for this without some refactoring would be pretty tough.


That's why I've asked :) Unfortunately I don't have the time to refactor the class (and add test for that too).


I believe this was addressed with #4973

@ralphschindler ralphschindler self-assigned this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 1 deletion.
  1. +7 −1 library/Zend/Db/Adapter/Driver/Pdo/Connection.php
8 library/Zend/Db/Adapter/Driver/Pdo/Connection.php
@@ -205,7 +205,7 @@ public function connect()
return $this;
- $dsn = $username = $password = $hostname = $database = null;
+ $dsn = $username = $password = $hostname = $database = $charset = null;
$options = array();
foreach ($this->connectionParameters as $key => $value) {
switch (strtolower($key)) {
@@ -240,6 +240,9 @@ public function connect()
case 'dbname':
$database = (string) $value;
+ case 'charset':
+ $charset = (string) $value;
+ break;
case 'driver_options':
case 'options':
$value = (array) $value;
@@ -267,6 +270,9 @@ public function connect()
if (isset($port)) {
$dsn[] = "port={$port}";
+ if (isset($charset)) {
+ $dsn[] = "charset={$charset}";
+ }
$dsn = $pdoDriver . ':' . implode(';', $dsn);
Something went wrong with that request. Please try again.