ChunkyMonk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using placeholders (in DBI/MySQL) on a set of INSERT statements;
however, when I try to fill a "?" placeholder with the value of NOW(), I just get the plain string "NOW()" in my data. Is there any way to tell the DBI/MySQL that the NOW() is supposed to be a current time function and not a plain string?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: Placeholders and NOW()
by runrig (Abbot) on Aug 15, 2002 at 02:36 UTC
    yes:
    sub NOW { # Return current time in whatever format it # Needs to be in } $sth->execute(NOW());
    But I suspect NOW() is a function in your particular database, in which case you wouldn't use a placeholder, and you would just put a literal NOW() in your SQL statement.

    Example:

    my $sth = $dbh->prepare(q{ INSERT INTO t ( foo, bar, time ) VALUES (?, ?, NOW() ) }); $sth->execute($foo, $bar);
      Instead of using a parameter that you'll bind at execute() time to the current time, include it instead directly in the query. For example, INSERT INTO t (msg, ts) VALUES(?, NOW())