Author Topic: How to pass mysql now() in PDO prepared statement ?  (Read 6518 times)

Savera

  • Full Member
  • ***
  • Posts: 159
How to pass mysql now() in PDO prepared statement ?
« 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.

Ricky

  • Full Member
  • ***
  • Posts: 180
Re: How to pass mysql now() in PDO prepared statement ?
« Reply #1 on: June 15, 2012, 04:08:25 PM »
 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.

 

X

Do you know?

IfAndBut.com gives you a platform where you can ask questions related to web and internet..
So, why wait..
Join Now!
anything