#!d:\perl\bin\perl.exe #path where the perl is installed. # To create a table that supports unicode in MySQL go to end of the page. # shanmukhan@gmail.com use DBI; use Encode; use Encode qw( from_to is_utf8 ); use utf8; my %val=(); $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if( $ENV{'REQUEST_METHOD'} eq "GET" ) { $buffer=$ENV{'QUERY_STRING'}; } my @pairs = split(/&/,$buffer); #split info into name/value pairs foreach my $pair (@pairs) { my ($name,$value) = split(/=/,$pair); $value=~ tr/+/ /; $value=~ s/%(..)/pack("C",hex($1))/eg; $FORM{$name}=$value; } $word=$FORM{'word'}; $flag=$FORM{'insert_retrieve'}; $meaning=$FORM{'meaning'} if($flag == 1); #-----------------------------data base part---------------------- # telugu is the data base name. Give user name, password. $dbh=DBI->connect("dbi:mysql:telugu",'root','root'); $st=$dbh->prepare("SET CHARACTER SET utf8;"); $st->execute(); $st=$dbh->prepare("SET SESSION collation_connection ='utf8_general_ci';"); $st->execute(); #telugu_dictionary is the table name. if( $flag == 0) { $st=$dbh->prepare("SELECT meaning FROM telugu_dictionary where word like \"$word\";"); $st->execute(); while( ($mean) = $st->fetchrow_array) { $meaning="$mean"; } } else { $st=$dbh->prepare("INSERT INTO telugu_dictionary (word,meaning) VALUES ('$word', '$meaning');"); $st->execute(); } $st->finish(); print "Content-type:text/html\n\n"; # statement which gives the output in a text/html form. if( $flag == 0) { print "$meaning"; } # To create a table in MySQL supporting unicode data. #CREATE TABLE `telugu_dictionary` ( # `word` varchar(250) default NULL, # `meaning` varchar(600) default NULL #) ENGINE=InnoDB DEFAULT CHARSET=utf8; 1;