T
timdavis919
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_ci 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 qwall);
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>This 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_row[0]</td>\n";
print " <td align=\"center\">$table_row[1]</td>\n";
print " <td align=\"center\">$table_row[2]</td>\n";
print " </tr>\n";
}
$sth->finish();
$dbh->do("UNLOCK TABLES");
print end_html;
#******************************************************************************
sub connect_to_DB
{
# database information
$db="*************************";
$host="localhost";
$port="3306";
$userid="****************";
$passwd="****************";
$connectionInfo="DBI:mysql:database=$db;$host:$port";
# make connection to database
$my_dbh = DBI->connect($connectionInfo,$userid,$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.
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_ci 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 qwall);
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>This 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_row[0]</td>\n";
print " <td align=\"center\">$table_row[1]</td>\n";
print " <td align=\"center\">$table_row[2]</td>\n";
print " </tr>\n";
}
$sth->finish();
$dbh->do("UNLOCK TABLES");
print end_html;
#******************************************************************************
sub connect_to_DB
{
# database information
$db="*************************";
$host="localhost";
$port="3306";
$userid="****************";
$passwd="****************";
$connectionInfo="DBI:mysql:database=$db;$host:$port";
# make connection to database
$my_dbh = DBI->connect($connectionInfo,$userid,$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.