List:General Discussion« Previous MessageNext Message »
From:Douglas Brantz Date:April 25 2000 6:29pm
Subject:OK - I'm learning DBI Connect
View as plain text  
Now everything seems to be working much better:
Here is a sample of the code and please offer if any suggestions
to clean this up.


The only error I'm getting now when I run the file from the command line
is:
Database handle destroyed without explicit disconnect, <STDIN> chunk 1.

My only source for help has been the O'REILLY Mysql & mSQL book.

#!/usr/bin/perl
#

#use strict;
use diagnostics;
use CGI;
use Mysql;
use DBI;

#Setup main program
my $query= new CGI;

#Print out a contect type for http/1.0 compatibility
print $query->header("text/html");

#Grab the values from the form
my $lab_title=$query->param("LABNAME");
#
#----- open database on Linux------------
#
my $dbh =
DBI->connect("DBI:mysql:database:localhost","username","password");
#
#-----Create the command---------------
#
my $command = "";
$command =<<"EOC";
insert into lab (lab_title) values ("$lab_title")
EOC
#
#
#---Uncomment for debugging-------------------
#
#print "<P>SQL command: \"$command\"</p>\n";
#
#
#--------Prepare the Command and Execute it---------------
#
my $sth = $dbh->prepare($command);

die "error with command \"$command\""
 unless (defined $sth);

$sth->execute;
#--------------------------------------------------------------
print<<END_OF_HTML;
<html>
<head>
<title>Lab Info</title>
</head>
<body>
<b>You have entered the following</b>
$lab_title
</body>
</html>
END_OF_HTML
exit;

--

Douglas Brantz
Computer Consultant
Fine & Applied Arts
Appalachian State University
Boone, NC 28608

828-262-6312 FAX
828-262-6549 OFFICE
brantzdr@stripped


Thread
OK - I'm learning DBI ConnectDouglas Brantz25 Apr
  • RE: OK - I'm learning DBI Connectindrek siitan25 Apr
  • RE: OK - I'm learning DBI Connectbenjamin-weiss25 Apr
    • Re: OK - I'm learning DBI ConnectThimble Smith26 Apr