Why does Perl DBI avoid values ​​derived from MySQL?

I have a value in MySQL that contains apostrophe ( ) and ellipsis ( ...):

$ /bin/echo "select alias from url_alias where source = 'node/12024'" | \
  mysql --skip-column-names -D cat36ia_d7prod

Conclusion:

forum/technical-discussion/nagging-questions-i’ve-been-too-embarrassed-ask…

When I get the value using Perl DBIand DBD::mysql, the value has been changed:

$ perl -MDBI -MDBD::mysql -e
      '$dbh=DBI->connect( "DBI:mysql:database=my_db",nick );
       $v=$dbh->selectrow_array(qq|select alias from url_alias where source = "'node/12024'"|);
       print "$v\n";'

Conclusion:

forum/technical-discussion/nagging-questions-i?ve-been-too-embarrassed-ask?

Why does Perl do this? Can I override it?

+4
source share
3 answers
  • Tell Perl how to encode the output.

    use open ':std', ':encoding(UTF-8)';
    
  • Retrieve data from a database as text using

    DBI->connect("DBI:mysql:database=my_db", $user, $pass, {
       mysql_enable_utf8 => 1,
    })
    
+6
source

You probably need to tell DBI to use UTF8 when talking to the database.

$dbh=DBI->connect(
   'DBI:mysql:database=my_db', $user, $pass,
   { mysql_enable_utf8 => 1 }
);
+3
source

Q: Perl ? ?

. . , , .


, Perl , : Perl STDOUT ascii. ASCII U + 00EF, (, 128 255) .

, , : , STDIN, STDOUT STDERR utf8, ascii, ​​ perl:

use open qw(:std :utf8);

MySQL session character_set_client; latin1, // utf8, .

, , .


, , :

, Unicode ( !)

,

+2
source

All Articles