in reply to Modifying Perl script to write to MySQL??

Almost there:

$sth=$dbh->prepare($guestbookreal); $sth->execute();

However, it is better if you use placeholders and put all your parameters as an argument of execute. That way all necessary quoting is done by the DBI/DBD.

And of course, you would also like to do some error checking, so you are sure the data made it into your database.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re: Re: Modifying Perl script to write to MySQL??
by Anonymous Monk on Feb 15, 2004 at 01:00 UTC
    Thanks so much CountZero! :-)

    That looks very much like what I thought might do it.
    I tried inserting your code (after the $guestbookurl line) but unfortunately something is returning a "500 Internal Server Error" ...

    So here's the script (obviously there's something I'm not seeing that's causing the snag...): Thanks once again for your help with this,

    -Bob
      Please don't use programs from Matt's Script Archive. They really aren't very good and you'll learn nothing but bad practices from reading that code. The guestbook at nms is a drop-in replacement for Matt's that is written in something approaching decent Perl :)
      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

      I think you have inserted the code I proposed too early. At that place in the script the SQL-statement is not yet written and moreover $guestbookreal just holds the name of the file where the SQL-statement will end up.

      So you will have to retrieve the contents of that file (you can do that between the

      close (GUEST); $dbh->disconnect;

      statements and then plug it into a dbh->prepare statement there. You can then execute the SQL and put the data in your database.

      Why Matt goes through so many hoops to do something which is rather easy to do, no-one at Perlmonks has ever been able to understand.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        (cont.)

        Perhaps what I'm asking is if there is a way to execute the output string going to/thru $guestbookreal to MySQL "on-the-fly?"

        $guestbookreal=>mysql??

        Hi CountZero,

        > moreover $guestbookreal just holds the name of the file where the SQL-statement will end up.

        But isn't that where the finished INSERT string/statement outputs to??
        $guestbookreal = "/home/flute/usedflutes-www/new_listings_publish.html +";
        http://usedflutes.com/new_listings_publish.html

        sorry, I'm somehow not getting the picture...

        Thanks again for your help CountZero,

        -Bob