Skip to content

Commit

Permalink
Feature/fix 256 (#257)
Browse files Browse the repository at this point in the history
* fix charset problem with sqlite, resolve #256

* Apply fixes from StyleCI
  • Loading branch information
romaninsh authored and DarkSide666 committed Nov 17, 2017
1 parent 1144ac0 commit 848e60a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Persistence.php
Expand Up @@ -44,18 +44,20 @@ public static function connect($dsn, $user = null, $password = null, $args = [])
$password = $parts['pass'];
}

// Omitting UTF8 is always a bad problem, so unless it's specified we will do that to prevent nasty problems.
if (strpos($dsn, ';charset=') === false) {
$dsn .= ';charset=utf8';
}

if (strpos($dsn, ':') === false) {
throw new Exception(["Your DSN format is invalid. Must be in 'driver:host:options' format", 'dsn' => $dsn]);
}
$driver = explode(':', $dsn, 2)[0];

switch (strtolower(isset($args['driver']) ?: $driver)) {
case 'mysql':
// Omitting UTF8 is always a bad problem, so unless it's specified we will do that
// to prevent nasty problems. This is un-tested on other databases, so moving it here.
// It gives problem with sqlite
if (strpos($dsn, ';charset=') === false) {
$dsn .= ';charset=utf8';
}

case 'dumper':
case 'counter':
case 'sqlite':
Expand Down

0 comments on commit 848e60a

Please sign in to comment.