I have a database table timetable
with a DATETIME
field called created_on
.
created_on DATETIME,
notes VARCHAR(255) NOT NULL
I use the NOW()
function to insert the current time through PDO prepared statements.
INSERT INTO timetable(created_on, note)
VALUES(?, ?);
So after binding the values and executing the prepared statement...
$notes ="This is a note...";
$values =array("NOW()", $notes);
$stm->execute($values);
... the notes
column in the MySQL table writes the expected data but the created_on
column produces...
0000-00-00 00:00:00
I don't want to use the Unix epoch timestamp. So how do I get DATETIME
in the NOW()
function to work?
don't pass NOW()
as a parameter,
INSERT INTO timetable(created_on, note) VALUES(NOW(), ?);
so you will only need to bind the notes.
$values =array($notes);
You are passing NOW()
as string, not mysql expression.
use as this:
INSERT INTO timetable(created_on, note)
VALUES(now(), ?);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With