Webmaster's Community
Designing and Development => Programming => Topic started by: Savera on June 15, 2012, 10:31:50 AM
-
Hi,
I am looking for a way to pass mysql now() function in PDO, I want to create something like following :
mysql_query("INSERT INTO tablename (id, value, time_created)
VALUES ('$id', '$value', NOW())");
But if I send NOW() in PDO as string ie as follows :
$stmt->bindParam(':created', NOW(), PDO::PARAM_STR);
It doesn't work and sends NULL value, please give me solution.
-
Just leave now in your query statement and should work, no need to bind it.
Do something like :
$stmt = $dbobj->prepare(INSERT INTO tablename (id, value, time_created) VALUES (:id, :value , NOW());
$stmt->bindValue(':id' , '234' , PDO::PARAM_INT);
$stmt->bindValue(':value' , 'Sunny' , PDO::PARAM_STR);
$stmt->execute();
I hope this helps. Point if I made any mistake.