We now show the complete program:
1. THE COMPLETE PERL PROGRAM:
#!/usr/bin/perl
MAIN:
{
use CGI;
use DBI;
$database="claywall";
$server="localhost";
$db_server=$server;
$user="root";
$password="04u2c_pixie!";
#Connect to the database
$dbh=DBI->connect("DBI:mysql:$database:$db_server",$user,$password);
$query = new CGI;
print $query->header;
print "\n<html>\n<body>";
print "\n<h1>SQL Queries<h1>";
#Drop table
$statement="drop table studios";
$sth=$dbh->prepare($statement);
$rv=$sth->execute;
print $statement."<br>";
#Create table
$statement="create table studios (id char(5), name char(20),
city char(20), state char(2))";
$sth=$dbh->prepare($statement);
$rv=$sth->execute;
print $statement."<br>";
#Insert data into table
$statement="insert into studios (id, name, city, state)
values ('5', 'big picture', 'Culver City', 'CA')";
$sth=$dbh->prepare($statement);
$rv=$sth->execute;
print $statement."<br>";
#Select from table
$statement="select * from studios";
$sth=$dbh->prepare($statement);
$rv=$sth->execute;
print $statement."<br>";
#Table header
print "\n<h1>student data<h1>";
print "\n<table border='1'>";
print "\n<tr>";
print "<td>id<td>";
print "<td>name<td>";
print "<td>city<td>";
print "<td>state<td>";
print "\n<tr>";
#Table records
while (@row=$sth->fetchrow_array)
{
print "\n<tr>";
print "\n<td>$row[0]<td>";
print "\n<td>$row[1]<td>";
print "\n<td>$row[2]<td>";
print "\n<td>$row[3]<td>";
print "\n<tr>";
}
print "\n<table>";
#Disconnect
$rc=$sth->finish;
$rc=$dbh->disconnect;
print "\n<body>\n<html>";
}
2. ACCESS TO THE COMPLETE PROGRAM:
You can access the complete program
here
|