Datetime NOW PHP mysql (+ PDO variant)

Viewed 74687

Thanks for looking. All helpful answers/comments are up voted.

In php, you can use NOW() like this:

mysql_query("INSERT INTO tablename (id,      value,      time_created) 
                            VALUES ('{$id}', '{$value}', NOW())");

How can I do the same thing in PDO. When I bind like this, I get an error:

$stmt->bindParam(':time_added', NOW(), PDO::PARAM_STR);

Is it the PDO:PARAM_STR?

6 Answers

Presuming your PDO statement is correct you could do something like this:

$date = date('Y-m-d H:i:s');
$stmt->bindParam(':time_added', $date, PDO::PARAM_STR);
Related