in reply to Re^2: Deleting Old MySql Records With PERL
in thread Deleting Old MySql Records With PERL

In addition to what perlfan said about SQL syntax, you also have a problem with perl syntax.

The DELETE statement is SQL, not perl. As such, it needs to be quoted, and passed to $dbh->do("SQL here");

Be careful to properly escape quotes, when passing SQL to do().

        There is no time like the present for postponing what you ought to be doing.

  • Comment on Re^3: Deleting Old MySql Records With PERL

Replies are listed 'Best First'.
Re^4: Deleting Old MySql Records With PERL
by Milti (Beadle) on Jul 13, 2016 at 23:47 UTC

    I'm now using this code. Still getting an error message.

    use DBI; use CGI ':standard'; print "Content-type: text/html\n\n"; my $dbh = DBI->connect('dbi:mysql:my_db','searcher','searcherpasswd') or die "Connection Error: $DBI::errstr\n"; $sth = $dbh->prepare ("DELETE FROM my table where DATE <UNIX_TIMESTAMP +(DATE_SUB(NOW()-INTERVAL 30 DAY)"); $sth->execute ();

    Error message ---- 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 syntax to use near '' at line 1 at e:\owner\cgi-bin\search_specialty.pl line 14.

    Line 14 is $sth->execute ();

      See perlfan's reply, below - where he explains that your column name, "date" is a reserved word, and therefore needs to be escaped using backticks.

      For more info, see this stackoverflow article.

              There is no time like the present for postponing what you ought to be doing.