Designing and Development > Programming

How to pass mysql now() in PDO prepared statement ?

(1/1)

Savera:
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.

Ricky:
 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.

Navigation

[0] Message Index

Go to full version