Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
It produces output like this:#!usr/bin/perl use DBI; use strict; my $one="one"; my $two="two"; my $three="three"; my $four="four"; # connect to the database, assigning the result to $dbh my $database="globalid"; my $host="autolabserver"; my $port="3306"; #connect to the database, assigning the result to $dbh my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host;port=$ +port", 'tester','auto55'); # die if we failed to connect die "Can't connect: " . DBI->errstr() unless $dbh; # all is well! print "Success: connected!\n"; my $sth = $dbh->prepare('INSERT INTO headerinfo (GLOBALID,DECIMAL,CONV +ERTED,COMMENT) VALUES(?,?,?,?)') or die "Can't prepare SQL: " . $dbh->errstr() +; $sth->execute($one,$two,$three,$four) or die "Can't execute SQL: " . $sth->errstr(); # finish and disconnect $dbh->disconnect(); print "finished";
It looks like its connecting to the databse alright, and I've checked that the database name and field names are correct. When I comment out the lines:Success: connected! finished C:\Documents and Settings\tester\Desktop\from diarmuid>perl connect.pl Success: connected! DBD::mysql::st execute failed: You have an error in your SQL syntax. +Check the manual that corresponds to your MySQL server version for the right syn +tax to use near 'DECIMAL,CONVERTED,COMMENT) VALUES('one at connect.pl line 28. Can't execute SQL: You have an error in your SQL syntax. Check the ma +nual that corresponds to your MySQL server version for the right syntax to use n +ear 'DECIM AL,CONVERTED,COMMENT) VALUES('one at connect.pl line 28.
No error message is produced. I think these two lines are causing the problem but I just can't see it.... Any Help is greatly appreciated.#$sth->execute($one,$two,$three,$four) # or die "Can't execute SQL: " . $sth->errstr();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl DBI question
by bassplayer (Monsignor) on Jun 22, 2004 at 13:31 UTC | |
by Anonymous Monk on Jun 22, 2004 at 13:35 UTC | |
by Grygonos (Chaplain) on Jun 22, 2004 at 13:51 UTC | |
|
Re: perl DBI question
by bradcathey (Prior) on Jun 22, 2004 at 14:50 UTC |