List:General Discussion« Previous MessageNext Message »
From:Douglas Brantz Date:April 25 2000 2:48pm
Subject:[Fwd: Need Assistance with DBI:Mysql]
View as plain text  

Douglas Brantz wrote:

>
> Wondered if  I could get some help with DBI connect.  I was using Mysql
> connect for all my
> scripts and they work fine, but wanted to take the time to learn how to
> connect with DBI - seems that everyone I talk to recommends.   Below is
> a sample script to insert data into a table and wondered if you could
> help point me in the right direction.  As is I get errors when I run it
> from the command line.  Something about EOF not at EOC ???  I think my
> problem is at the connect line.  Any help would be greatly appreaciated.
>
> Thanks
>
> #!/usr/bin/perl -w
> #
>
> #use strict;     ##When I try to use strict the file wont run when I do
> ./lab.pl at the command line.
> use diagnostics;
> use CGI;
> use Mysql;     ##not sure if I should leave this in the program at all
> -thought the mysql.pm had DBI connect statements:
> use DBI;        ## If mysql will work for the DBI connect should I not use
> this line?
>
> #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");
> my $command="";
> $command = << "EOC";
> Insert into tablename lab_title=$lab_title   ###Should this be insert
> into lab(lab_title)values($lab_title)
> EOC
>
> my $sth = $dbh->query($command); ###  Should these lines be different if I
> am using DBI?
> die "error with command \"$command\""
>       unless (defined $sth);
> #----------------------------------------------------------------#I am
> also trying it this way.

my $dbh = DBI->connect("DBI:mysql:database:localhost":"free":"free");
my $insert="Insert into tablename(lab_title)values($lab_title)";

my $sth = dbh->prepare($insert);
$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

--

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

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


Thread
[Fwd: Need Assistance with DBI:Mysql]Douglas Brantz25 Apr