I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st execute failed: You have an error in your SQL syntax near 'hlt' instruction... OK. ')' at line 1 at ./logger_test.pl line 21, <LOG> line 40. The one second sleep, and the print in the script is so I can see what is going on, otherwise it is scrolling way to fast Script: ============================================================================ ========= #!/usr/bin/perl -wT # use DBI; $dsn = "DBI:mysql:servers:localhost"; $user_name = "user"; $passwd = "password"; $log = "/var/log/messages"; $dbh = DBI->connect ($dsn, $user_name, $passwd, {RaiseError => 1}); open(LOG, $log) || die "Can't open $log: $!\n"; while (<LOG>) { ($month, $day, $time, $logged_host, $service, $description) = split / /, $_, 6; print "$month $day $time $logged_host $service $description\n"; sleep 1; $sth = $dbh->prepare( "INSERT INTO status values ('$month', '$day', '$time', '$logged_host', '$service', '$description')" ); $sth->execute (); $sth->finish (); } $dbh->disconnect (); close(LOG);
![]() |
-3 |
![]() |
On Wed, 30 May 2001, Paul Fontenot wrote: > I am getting this error and I know what is causing it, but I have no idea > how to fix it, any help would be great. The script steps through the > /var/log/messages file on a linux server and puts > The entries into a mysql database. However when it gets to the 'hlt' line in > the messages file it just barfs. The single quotes are freaking it out. I > know about quotes but not how to use in > this situation. Use the placeholders ? in the prepare statement and pass the variables with execute statement as described in the documentation Regards herbie -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Herbert Liechti E-Mail: Herbert.Liechti@thinx.ch ThinX networked business services Adlergasse 5, 4500 Solothurn ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
![]() |
-3 |
![]() |
From: "Paul Fontenot" <paul@pitbull-racing.com> To: <dbi-users@perl.org> Subject: quotes, quotes, quotes... Date sent: Wed, 30 May 2001 23:58:49 -0700 Paul, use placeholders as follows (and add error checking yourself): > ============================================================================ > ========= > #!/usr/bin/perl -wT > # > use DBI; > > $dsn = "DBI:mysql:servers:localhost"; > $user_name = "user"; > $passwd = "password"; > > $log = "/var/log/messages"; > > $dbh = DBI->connect ($dsn, $user_name, $passwd, {RaiseError => 1}); > # prepare $sth *now* $sth = $dbh->prepare( "INSERT INTO status values (?, ?, ?, ?, ?, ?)" ); > open(LOG, $log) || die "Can't open $log: $!\n"; > > while (<LOG>) { > ($month, $day, $time, $logged_host, $service, $description) = split > / /, $_, 6; > print "$month $day $time $logged_host $service $description\n"; > sleep 1; > $sth->execute ($month, $day, $time, $logged_host, $service, $description); > } > > $dbh->disconnect (); > close(LOG); > Dr. med. Bodo Eing Institut fuer Medizinische Mikrobiologie Klinische Virologie v.-Stauffenbergstr. 36 48151 Muenster Germany Phone: ++49 251 7793 111 Fax: ++49 251 7793-104
![]() |
3 |
![]() |
Thanks for the gentle nudge. As usual the list is absolutely correct and most appreciated. -Paul -----Original Message----- From: Herbert.Liechti@thinx.ch [mailto:Herbert.Liechti@thinx.ch] Sent: Thursday, May 31, 2001 12:01 AM To: Paul Fontenot Cc: dbi-users@perl.org Subject: Re: quotes, quotes, quotes... On Wed, 30 May 2001, Paul Fontenot wrote: > I am getting this error and I know what is causing it, but I have no idea > how to fix it, any help would be great. The script steps through the > /var/log/messages file on a linux server and puts > The entries into a mysql database. However when it gets to the 'hlt' line in > the messages file it just barfs. The single quotes are freaking it out. I > know about quotes but not how to use in > this situation. Use the placeholders ? in the prepare statement and pass the variables with execute statement as described in the documentation Regards herbie -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Herbert Liechti E-Mail: Herbert.Liechti@thinx.ch ThinX networked business services Adlergasse 5, 4500 Solothurn ~~~~~~~~~~~~~~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