I would like to update a DATETIME
mysql field using a php STRING
in a prepared statement
$stmt = $mysqli->prepare("UPDATE TABLE1 SET DATETIME1 = ? where ID = ?");
$stmt->bind_param('si',$date,$id);
$date = "2013-12-04 00:00:00"; /*string '2013-12-04 00:00:00' (length=19)*/
$id = 4;
$stmt->execute();
I had expect that mysql should treat the statement as
UPDATE TABLE1 SET DATETIME1 = '2013-12-04 00:00:00' where ID = ?;
/*which works when directly entered*/
However I assume it is treating like
UPDATE TABLE1 SET DATETIME1 = 2013-12-04 00:00:00 where ID = ?;
/*giving the result of null*/
I have tried adding using the STR_TO_DATE
mysql function to force it to treat the $date as a string and then convert it to DATETIME
. ie
$stmt = $mysqli->prepare("UPDATE TABLE1 SET DATETIME1 = STR_TO_DATE(?,'%Y-%m-%d %T') where ID = ?");
/*again the result is null*/
Do I need to bind a quoted string? what am I missing?