On Wed, Jun 06, 2001 at 10:43:52AM -0400, Jeff Boes wrote:
>
> I have a date expression in a scalar like this:
>
> $mydate = q!timestamp 'today' - interval '30 days'!;
>
> I want to execute a statement like this:
>
> $stmt = $dbh->prepare('SELECT * FROM foo WHERE date_added > ?');
> $stmt->execute($mydate);
You can't. Placeholders may only be used with simple values.
timestamp 'today' - interval '30 days' is an expression.
> DBD::Pg reports that the date is invalid. But if I change this to
>
> $stmt = $dbh->prepare("SELECT * FROM foo WHERE date_added > $mydate");
>
> it's fine. What am I missing here?
Try:
$stmt = $dbh->prepare(<<'EndOfSQL');
SELECT * FROM foo
WHERE date_added > timestamp 'today' - interval ?
EndOfSQL
$interval = '30 days';
$stmt->execute($interval);
Ronald