Changeset 32640 for main/trunk/greenstone2/perllib/gsmysql.pm
- Timestamp:
- 2018-11-29T21:23:49+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/gsmysql.pm
r32595 r32640 208 208 $params_map->{'db_encoding'} = $self->{'db_encoding'}; 209 209 $params_map->{'verbosity'} = $self->{'verbosity'}; 210 210 211 211 $self->{'db_handle'} = &_get_connection_instance($params_map); # getting singleton (class method) 212 212 if($self->{'db_handle'}) { … … 240 240 241 241 # For proper utf8 support in MySQL, encoding should be 'utf8mb4' as 'utf8' is insufficient 242 my $db_enc = "utf8mb4" if $params_map->{'db_encoding'} eq "utf8";242 my $db_enc = ($params_map->{'db_encoding'} eq "utf8") ? "utf8mb4" : $params_map->{'db_encoding'}; 243 243 244 244 # Params for connecting to MySQL … … 287 287 RaiseError => 0, # off by default, but being explicit 288 288 AutoCommit => $autocommit, 289 mysql_enable_utf8mb4 => 1 # tells MySQL to use (4 byte) UTF-8 for 290 # communication and tells DBD::mysql to use it to decode the data, 289 #mysql_enable_utf8mb4 => 1 # Unrecognised in Windows' Strawberry Perl 5.22. On Ubuntu perl 5.22 290 # if mysql_enable_utf8mb4 was set to 1 *during connect()*, this tells MySQL to use (4 byte) UTF-8 for 291 # communication AND tells DBD::mysql to use it to decode the data, 291 292 # see https://stackoverflow.com/questions/46727362/perl-mysql-utf8mb4-issue-possible-bug 292 293 }); … … 322 323 # (see https://www.perlmonks.org/?node_id=259456) 323 324 324 #my $stmt = "set NAMES '" . $db_enc . "'"; 325 #$dbh->do($stmt) || warn("Unable to set charset encoding at db server level to: " . $db_enc . "\n"); # tells MySQL to use UTF-8 for communication 326 #$dbh->{mysql_enable_utf8mb4} = 1; # tells DBD::mysql to decode the data 325 # For Strawberry Perl 5.22, need to the following 2 steps here to take care of encoding issues 326 # The 2 steps are: set names utf8mb4; AND setting mysql_enable_utf8mb4 = 1 327 # Doing this in 2 steps here also works on Ubuntu perl 5.22, 328 # but that also supported setting mysql_enable_utf8mb4 to 1 during connect() 329 # to do both these steps in one go 330 my $stmt = "set NAMES '" . $db_enc . "'"; 331 $dbh->do($stmt) || warn("Unable to set charset encoding at db server level to: " . $db_enc . "\n"); # tells MySQL to use UTF-8 for communication 332 $dbh->{mysql_enable_utf8mb4} = 1; # tells DBD::mysql to decode the data 327 333 328 334 # if we're here, then connection succeeded, store handle
Note:
See TracChangeset
for help on using the changeset viewer.