in reply to Re^2: Trouble with Perl MySQL Arabic
in thread Trouble with Perl MySQL Arabic
If the data in the "fixed" table still looks buggy, you might try the following alterations to the OP code, just to see if this makes a difference (I don't know whether it will):
(updated to remove redundant "my" declarations on $sqlstatement and $sth)use Encode; # add this near the top my $sqlstatement = 'select name_arabic from data'; my $sth = $dbh->prepare($sqlstatement); $sth->execute || die "Could not execute MySQL statement: $sqlstatement +"; my @row; my @cases; # if handling only one field, let's make this a plain array while (@row=$sth->fetchrow_array) { # explicitly convert to utf8 (die +on failure) push @cases, decode( 'cp1256', $row[0], Encode::FB_CROAK ); } $sth->finish(); # optimize a little: the insert statement only needs to be prepared on +ce $sqlstatement = 'insert into newdb.names (arabicname) values (?)'; $sth = $dbh->prepare($sqlstatement); for my $i (0..$#cases) { # now explicitly convert back to cp1256 $sth->execute( encode( 'cp1256', $cases[$i] )) or die "putsql could not execute MySQL statement: $sqlstateme +nt"; } $sth->finish();
|
|---|