I'm trying to update my MySQL database with a DateTime variable.
$interval = 'P' . $days . 'DT' . $hours. 'H' . $minutes. 'M' . $seconds . 'S' ;
$date = new DateTime("NOW");
$date->add(new DateInterval($interval));
Now the SQL update:
$query = "UPDATE table
SET table.table_date = '$date' ";
mysql_query($query);
mysql_query($query);
If I var_dump the $date variable, it shows the right properties:
object(DateTime)#4 (3) { ["date"]=> string(19) "2012-07-05 20:04:14" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" }
but it just wont be inserted. If I try NOW() instead of $date, it works perfectly. Whats my mistake?
mysql_extensions, whose use is discourage and which will probably be removed from PHP soon. Using prepared statements should also solve this problem.