in reply to unicode file in mysql

the following code is incomplete, I expect you will have to read a few perldocs for the CGI and DBI and DBD::mysql modules to fill it in and make sure everything is how it should be:
#/usr/bin/perl -w use strict; use CGI; use DBI; #start our CGI object up my $Q = CGI->new(); #we probably want to set $CGI::POST_MAX, too. #initialize a DB handle my $dsn = 'username:host:password'; #see perldocs for exact form my $DBH = DBI->new( $dsn ); #check for a file my $file = $Q->param( 'uploaded_file' ); unless ( $file ) { #there is no file upload, so here's the form to do the upload print $Q->header(), $Q->start_html(), $Q->start_form(); print $Q->filefield( -name => 'uploaded_file' ); print $Q->end_html(); exit; } my $text = join( '', <$filename> ); #slurp the whole file up $DBH->do("INSERT INTO table VALUES( '$text' )"); #assumes blob or unic +ode text field in target table #status back to user print $Q->header(), $Q->start_hmtl, $Q->p( 'Done' ), $Q->end_html;

Update: as to the unicode format issue, you can probably convert that stuff to HTML entities before you insert it, otherwise you might look at the blob field type (not ideal, but might work), after all, on some level it's just data.

Replies are listed 'Best First'.
Re: Re: unicode file in mysql
by coeur2v (Initiate) on Aug 21, 2001 at 01:18 UTC
    Thanks for your reply ichimunki, My major problem concerns the unicode format. I do not no how to convert it in standard text and html. I assume that I have to use the unicode module, but I am very short in time so any help is welcome.

      Actually Text::Iconv is your friend.

      #!/usr/bin/perl -w use strict; use Text::Iconv; use HTML::Entities; # create the conversion method (only once) my $conv = Text::Iconv->new("utf8", "latin1"); my $html_text = encode_entities( $conv->convert( $utf8_text));

      If you want to get fancy you can use the bit of code in converting character encodings

        Thank you for your help, but this module is not installed on my ISP'server.... :-(
        Do you know a method to do the same thing without using this module ?
      I figured as much, you should be more specific in the question then! :)

      Unicode::String is the module I would look at. It appears to supply methods for converting unicode into a variety of more 8-bit friendly forms.