Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added optional charset to pdo dsn #5064

Closed
wants to merge 2 commits into from

3 participants

@stefankleff

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 :)

@EvanDotPro
Collaborator

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.

@stefankleff

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

@ralphschindler
Collaborator

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
View
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;
break;
+ 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}";
+ }
break;
}
$dsn = $pdoDriver . ':' . implode(';', $dsn);
Something went wrong with that request. Please try again.