DBI/PERL Tutorial over the Web

Click to go to the PREVIOUS page. Click to go to the INDEX page.

SLIDE #10 THE COMPLETE PROGRAM


We now show the complete program:

1. THE COMPLETE PERL PROGRAM:

#!/usr/bin/perl
MAIN:
{
        use CGI;
	use DBI qw(:sql_types);
	use DBD::Oracle qw(:ora_types);
	$host   = "delphi.acast.nova.edu:3877";
	$sid    = "NSU8I";
	$user   = "jclevin";
	$password = "scis1";
	$database = "delphi8";
	$ENV{ORACLE_SID}   = "NSU8I";
	$ENV{ORACLE_HOME}  = "/home/oracle/product/815";
	$dbh = DBI->connect("dbi:Oracle:$database", $user, $password, { PrintError => 0, 
AutoCommit => 0 }) or die "Unable to connect to $database: $DBI: :errstr\n";
	$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


© Copyright 2002 International Customized Software Co.