Content of the file "InsertData.pl":

#!/usr/local/bin/perl -w

#*******************************************

# INSERT data into a Table in the DATABASE

# by Hanh Pham

#*******************************************

 

use DBI;

 

my $database = 'ecity'; # your_database_name

my $user = 'ecity'; # 'your_user_name MySQL

my $password = '112233'; # your_password MySQL

 

# CONNECT to the Database

#..............................................................

$dbh = DBI->connect("DBI:mysql:${database}:zodiac.cs.newpaltz.edu:3306",

$user, $password)

or die "Wrong Database or Username or Password\n";

 

# Send QUERY to the Database (INSERT into table "users")

#..............................................................

$dbh->do("INSERT INTO users VALUES ('002','zzz','bbb','student','ai.com');"

) or print "errors in INSERT to Database.";

 

$dbh->disconnect;

 

print "Data was INSERTED succesfully.\n";

 

Content of the file "ReadData.pl":

#!/usr/local/bin/perl -w

#*******************************************

# READ data from a Table in the DATABASE

# (by Hanh Pham)

#*******************************************

 

use DBI;

#use strict;

 

my $database = 'ecity'; # your_database_name

my $user = 'ecity'; # 'your_user_name MySQL

my $password = '112233'; # your_password MySQL

 

my ($dbh, $sth); # database and statement handles

my (@ary); # array for rows returned by query

 

 

# CONNECT to the Database

#..............................................................

$dbh = DBI->connect("DBI:mysql:${database}", $user, $password)

or die "Wrong Database or Username or Password\n";

 

# Send QUERY to the Database (READ data from the table "users")

#..............................................................

 

# issue query

my $query = qq{ SELECT PASSWORD,USERNAME

FROM users

WHERE UID=1 };

 

# send query

$dbh->do($query) or print "errors in INSERT to Database.";

 

$sth = $dbh->prepare( $query );

$sth->execute();

 

my @a;

 

# read results of query, then clean up

while (@ary = $sth->fetchrow_array ())

{

push(@a,@ary); # save the result as @ary will be cleaned;

}

$sth->finish();

 

$dbh->disconnect;

 

# PRODUCE a Reply HTM file

#....................................

 

my $name;

my $pass;

 

($name,$pass)=@a[0,1];

 

use CGI qw( :standard );

my $q = new CGI;

print $q->header("text/html");

 

print <<End_Success;

<HTML>

<HEAD>

<TITLE>Result</TITLE>

</HEAD>

<BODY TEXT="#000000" LINK="#0000ff" VLINK="#800080""><br>

Your User Name : <FONT COLOR = "BLUE"><B>$name</B></FONT><br>

Your Password : <FONT COLOR = "BLUE"><B>$pass</B></FONT><br><br>

</BODY></HTML>

End_Success