public
Created

  • Download Gist
parsedsn.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12
#!perl
 
use DBI;
 
my $dsn = 'dbi:mysql(charset=>utf8mb4,RaiseError=>1):dbname=foo;host=localhost;';
my $dsa = [ DBI->parse_dsn($dsn) ];
my $charset = delete $dsa->[3]->{charset};
 
$dsn = sprintf("%s:%s(%s):%s", $dsa->[0], $dsa->[1], join(',', map { $_ . "=>" . $dsa->[3]->{$_} } keys %{ $dsa->[3] }), $dsa->[4]);
 
use Data::Dumper;
warn Dumper [$dsn, $charset];

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.