Anon
Anon

Reputation: 1221

Send a PHP variable to the DATE_ADD() SQL function?

I'd like to use a variable number of seconds ($seconds_to_add) in the DATE_ADD() function but it dosen't work. Is it possible ?

<?php
$requete = $pdo->prepare('UPDATE pages SET
    vote_time_limit =  DATE_ADD(vote_time_limit, INTERVAL :seconds_to_add SECOND)
    WHERE page_ID=:id_page');

$requete->bindValue(':id_page', $id_page);
$requete->bindValue(':seconds_to_add', $seconds_to_add);

Upvotes: 0

Views: 475

Answers (1)

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 174997

Bind it as an int, because the default is a string (which includes quotes).

$requete->bindValue(':seconds_to_add', $seconds_to_add, PDO::PARAM_INT);

I recommend you do it on the ID too.

Upvotes: 1

Related Questions