views:

450

answers:

2

Hi, does exist some PDO::PARAM_??? which can be used for dates or timestamps?

$sql = "UPDATE my_table SET current_date = :date WHERE id = 43";
$statement = $pdo->prepare ($sql);
$statement->bindParam (":date", strtotime (date ("Y-m-d H:i:s")), PDO::PARAM_STR);
$statement->execute ();
A: 

Nope. Treat date as a string.

Col. Shrapnel
A: 

When writing a date in an SQL query, you are writing it as a string ; you have to do the same with prepared statements, and use PDO::PARAM_STR, like you did in the portion of code you proposed.

And for the "timestamp", if by "timestamp" you mean :

  • The MySQL timestamp data-type : it's the same, you'll pass it as a string
  • The PHP UNIX timestamp, which is an integer : you'll pass it an an int.
Pascal MARTIN