Cyrillic web pages with Perl and MySQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • timdavis919@hotmail.com

    Cyrillic web pages with Perl and MySQL

    I'm trying to build some Russian web pages using Perl and MySQL. Toward
    that end, I have created a simple test case, which does not seem to
    work. Any help would be appreciated.

    I can successfully create a table in MySQL 4.1 with these commands
    (this creates a table with three rows; the three columns in each row
    are 1) an integer primary key, 2) a russian word, and 3) an english
    word):

    ----------------------------------------------------------------------------------------------------------------------
    create table WORDS
    (
    WORD_ID integer NOT NULL AUTO_INCREMENT,
    RUSS_WORD varchar(64) CHARACTER SET koi8r COLLATE
    koi8r_general_c i not null,
    ENG_WORD varchar(64) CHARACTER SET latin1 COLLATE
    latin1_german1_ ci not null,
    primary key (WORD_ID),
    UNIQUE WORD_ID (WORD_ID)
    );

    INSERT INTO WORDS VALUES (0, 'Привет.' , 'Hi.');
    INSERT INTO WORDS VALUES (0, 'Интерне т', 'Internet');
    INSERT INTO WORDS VALUES (0, 'очень', 'very');
    ----------------------------------------------------------------------------------------------------------------------
    I entered these commands through the phpMyAdmin interface.

    When I use the phpMyAdmin interface to look at the WORDS table, I see
    the English and Cyrillic words and everything looks fine.

    This is my simple Perl Script to display the database table on a web
    page. For some reason it does not display the Cyrillic words correctly:

    ----------------------------------------------------------------------------------------------------------------------
    #!/usr/local/bin/perl -w
    use CGI qw(:all);

    print "Content-type: text/html\n\n";
    print "<html>\n";
    print "<head>\n";
    print "<title>Thi s is a test</title>\n";
    print "<meta http-equiv=\"Content-Type\" content=\"text/html\;
    charset=koi8-r\">\n";

    print "</head>\n";
    print "<body>\n";
    print "<h3>This is a test</h3>\n";

    #-----------------------------------------------------------------------------
    #Open Connection to database ---------------------------------
    #-----------------------------------------------------------------------------
    print "Trying to open connection to the database...<br> \n";
    use DBI;
    $dbh = connect_to_DB() ;
    print "Database connection opened...<br>\n ";

    #-----------------------------------------------------------------------------
    #Print the web page -------------------------------------------------
    #-----------------------------------------------------------------------------
    print "<br>This is the WORDS table in the database.<br>\n ";
    print "<table width=\"90%\" border=\"1\" align=\"center\ ">\n";
    print " <tr>\n";

    $dbh->do("LOCK TABLES WORDS READ");
    $query = "SELECT * FROM WORDS";
    $sth = $dbh->prepare($query );
    $sth->execute();

    while (my @table_row = $sth->fetchrow_array ())
    {
    print " <td align=\"center\ ">$table_ro w[0]</td>\n";
    print " <td align=\"center\ ">$table_ro w[1]</td>\n";
    print " <td align=\"center\ ">$table_ro w[2]</td>\n";
    print " </tr>\n";
    }

    $sth->finish();
    $dbh->do("UNLOCK TABLES");

    print end_html;

    #************** *************** *************** *************** *************** ****
    sub connect_to_DB
    {
    # database information
    $db="********** *************** ";
    $host="localhos t";
    $port="3306";
    $userid="****** **********";
    $passwd="****** **********";
    $connectionInfo ="DBI:mysql:dat abase=$db;$host :$port";

    # make connection to database
    $my_dbh = DBI->connect($conne ctionInfo,$user id,$passwd)|| die
    "Database connection not made: $DBI::errstr";
    return ($my_dbh);

    }
    #************** *************** *************** *************** *************** ****
    ----------------------------------------------------------------------------------------------------------------------

    The web page prints out the table correctly, but the Cyrillic words
    come out as "?????".

    I can use the same web browser to look at other Cyrillic web pages, and
    those display fine.

    I also tried the same thing using windows-1251 Cyrillic, but the
    results were the same.

    Any helpful suggestions from those with experience would be most
    welcome.

  • Smike

    #2
    Re: Cyrillic web pages with Perl and MySQL

    Instead of using "direct" Cyrillic string use its Unicode presentetion
    for example Cyrillic "Privet" would be presented as
    Привет

    your Perl script should write
    print "<html>\n";
    print "<head>\n";
    print "</head>\n";
    print "<body>\n";
    print "<font color=\"#ff0000 \" size=\"3\">\n";
    print "Привет\n";
    print "<\font>\n" ;
    print "</body>\n";
    print "</html>\n";

    No charset metas is required IExplorer and Netscape recognize
    Cyrillic/Greek/Hebrew automatically and correct.

    to convert Cyrillic string to codes use editor DELO


    Format menu->Code Conversion->Symbols to HTML
    CONVERTED STRING SHOULD BE SELECTED (Highlighted)

    Example of Cyrillic page with such presentation is


    Comment

    Working...